Skip to content

Commit

Permalink
Fix RSpec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelaferreira committed Mar 18, 2016
1 parent 03a9d32 commit d584ece
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def res_name
end

# @return [String] Name of the user that runs nginx
def user_for_platform
def user_for_platform(node)
case node['platform']
when 'centos'
'nginx'
Expand Down
2 changes: 1 addition & 1 deletion libraries/resource_nginx_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NginxService < Chef::Resource::LWRPBase
attribute :error_log_level, kind_of: String, default: 'warn'
attribute :run_group, kind_of: String, default: nil
# @todo Determine what user is correct per-platform
attribute :run_user, kind_of: String, default: lazy { user_for_platform }
attribute :run_user, kind_of: String, default: lazy { user_for_platform(node) }
attribute :worker_connections, kind_of: Integer, default: 1024
attribute :worker_processes, kind_of: Integer, default: 1

Expand Down
8 changes: 4 additions & 4 deletions spec/libraries_specs/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ def initialize
@dummy.extend NginxCookbook::Helpers
end

it 'returns www-data for debin platform' do
it 'returns www-data for debian platform' do
@dummy.node['platform'] = 'debian'

expect(@dummy.user_for_platform).to be == 'www-data'
expect(@dummy.user_for_platform(@dummy.node)).to be == 'www-data'
end

it 'returns www-data for ubuntu platform' do
@dummy.node['platform'] = 'ubuntu'

expect(@dummy.user_for_platform).to be == 'www-data'
expect(@dummy.user_for_platform(@dummy.node)).to be == 'www-data'
end

it 'returns nginx for centos platform' do
@dummy.node['platform'] = 'centos'

expect(@dummy.user_for_platform).to be == 'nginx'
expect(@dummy.user_for_platform(@dummy.node)).to be == 'nginx'
end

# # let(:klass) { Class.new { extend NginxCookbook::Helpers } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :create', 'example', 'platform' => 'centos'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #upstart', 'example'
it_behaves_like 'nginx_service #systemd', 'example'

it_behaves_like 'nginx_config :create', 'example'
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :create', 'example', 'platform' => 'debian'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #upstart', 'example'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :create', 'example', 'platform' => 'ubuntu'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #sysvinit', 'example'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it_behaves_like 'create a named nginx_service', 'example'

it_behaves_like 'nginx_service :create', 'example'
it_behaves_like 'nginx_service :create', 'example', 'platform' => 'ubuntu'
it_behaves_like 'nginx_service :start', 'example'
it_behaves_like 'nginx_service #upstart', 'example'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it_behaves_like 'create a named nginx_service', 'single'

it_behaves_like 'nginx_service :create', 'single'
it_behaves_like 'nginx_service :create', 'single', 'platform' => 'centos'
it_behaves_like 'nginx_service :start', 'single'

xit 'stops the service' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it_behaves_like 'create a named nginx_service', 'single'

it_behaves_like 'nginx_service :create', 'single'
it_behaves_like 'nginx_service :create', 'single', 'platform' => 'debian'
it_behaves_like 'nginx_service :start', 'single'

xit 'stops the service' do
Expand Down
11 changes: 9 additions & 2 deletions spec/shared_examples/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end
end

shared_examples_for 'nginx_service :create' do |servicename|
shared_examples_for 'nginx_service :create' do |servicename, node|
it 'installs the nginx package' do
expect(chef_run).to install_package("#{servicename} :create nginx")
.with(package_name: 'nginx')
Expand All @@ -21,7 +21,7 @@

it 'creates new directories for the named instance' do
expect(chef_run).to create_directory("/var/log/nginx-#{servicename}")
.with(user: user_for_platform, group: 'adm', mode: 00755)
.with(user: user_for_platform(node), group: 'adm', mode: 00755)

%W(
/etc/nginx-#{servicename}
Expand Down Expand Up @@ -63,4 +63,11 @@
.with(user: 'root', group: 'root', mode: 00744)
end
end

shared_examples_for 'nginx_service #systemd' do |servicename|
it 'templates instance-specific files' do
expect(chef_run).to create_template("/etc/nginx-#{servicename}/nginx.conf")
.with(user: 'root', group: 'root', mode: 00644)
end
end
end

0 comments on commit d584ece

Please sign in to comment.