Skip to content

Commit

Permalink
add npm to package provider
Browse files Browse the repository at this point in the history
  • Loading branch information
linyows committed May 28, 2013
1 parent f0ba090 commit 9a75a97
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/serverspec/commands/base.rb
Expand Up @@ -128,6 +128,12 @@ def check_installed_by_gem name, version=nil
cmd
end

def check_installed_by_npm name, version=nil, path=nil
cmd = "#{path || 'npm'} ls #{escape(name)} -g"
cmd = "#{cmd} | grep -w -- #{escape(version)}" unless version.nil?
cmd
end

def check_belonging_group user, group
"id #{escape(user)} | awk '{print $3}' | grep -- #{escape(group)}"
end
Expand Down
2 changes: 2 additions & 0 deletions spec/darwin/matchers_spec.rb
Expand Up @@ -43,6 +43,8 @@

it_behaves_like 'support be_installed.by(gem) matcher', 'jekyll'
it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
it_behaves_like 'support be_installed.by(npm) matcher', 'bower'
it_behaves_like 'support be_installed.by(npm).with_version matcher', 'bower', '0.9.2'

it_behaves_like 'support belong_to_group matcher', 'root', 'root'
it_behaves_like 'support have_gid matcher', 'root', 0
Expand Down
2 changes: 2 additions & 0 deletions spec/darwin/package_spec.rb
Expand Up @@ -5,4 +5,6 @@
describe 'Serverspec package matchers of Darwin family' do
it_behaves_like 'support package installed by gem matcher', 'jekyll'
it_behaves_like 'support package installed by gem with version matcher', 'jekyll', '1.1.1'
it_behaves_like 'support package installed by npm matcher', 'bower'
it_behaves_like 'support package installed by npm with version matcher', 'bower', '0.9.2'
end
2 changes: 2 additions & 0 deletions spec/debian/matchers_spec.rb
Expand Up @@ -43,6 +43,8 @@

it_behaves_like 'support be_installed.by(gem) matcher', 'jekyll'
it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
it_behaves_like 'support be_installed.by(npm) matcher', 'bower'
it_behaves_like 'support be_installed.by(npm).with_version matcher', 'bower', '0.9.2'

it_behaves_like 'support belong_to_group matcher', 'root', 'root'
it_behaves_like 'support have_gid matcher', 'root', 0
Expand Down
2 changes: 2 additions & 0 deletions spec/debian/package_spec.rb
Expand Up @@ -6,4 +6,6 @@
it_behaves_like 'support package installed matcher', 'httpd'
it_behaves_like 'support package installed by gem matcher', 'jekyll'
it_behaves_like 'support package installed by gem with version matcher', 'jekyll', '1.1.1'
it_behaves_like 'support package installed by npm matcher', 'bower'
it_behaves_like 'support package installed by npm with version matcher', 'bower', '0.9.2'
end
2 changes: 2 additions & 0 deletions spec/gentoo/matchers_spec.rb
Expand Up @@ -44,6 +44,8 @@

it_behaves_like 'support be_installed.by(gem) matcher', 'jekyll'
it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
it_behaves_like 'support be_installed.by(npm) matcher', 'bower'
it_behaves_like 'support be_installed.by(npm).with_version matcher', 'bower', '0.9.2'

it_behaves_like 'support belong_to_group matcher', 'root', 'root'
it_behaves_like 'support have_gid matcher', 'root', 0
Expand Down
2 changes: 2 additions & 0 deletions spec/gentoo/package_spec.rb
Expand Up @@ -6,4 +6,6 @@
it_behaves_like 'support package installed matcher', 'httpd'
it_behaves_like 'support package installed by gem matcher', 'jekyll'
it_behaves_like 'support package installed by gem with version matcher', 'jekyll', '1.1.1'
it_behaves_like 'support package installed by npm matcher', 'bower'
it_behaves_like 'support package installed by npm with version matcher', 'bower', '0.9.2'
end
2 changes: 2 additions & 0 deletions spec/redhat/matchers_spec.rb
Expand Up @@ -45,6 +45,8 @@

it_behaves_like 'support be_installed.by(gem) matcher', 'jekyll'
it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
it_behaves_like 'support be_installed.by(npm) matcher', 'bower'
it_behaves_like 'support be_installed.by(npm).with_version matcher', 'bower', '0.9.2'

it_behaves_like 'support belong_to_group matcher', 'root', 'root'
it_behaves_like 'support have_gid matcher', 'root', 0
Expand Down
2 changes: 2 additions & 0 deletions spec/redhat/package_spec.rb
Expand Up @@ -6,4 +6,6 @@
it_behaves_like 'support package installed matcher', 'httpd'
it_behaves_like 'support package installed by gem matcher', 'jekyll'
it_behaves_like 'support package installed by gem with version matcher', 'jekyll', '1.1.1'
it_behaves_like 'support package installed by npm matcher', 'bower'
it_behaves_like 'support package installed by npm with version matcher', 'bower', '0.9.2'
end
2 changes: 2 additions & 0 deletions spec/solaris/matchers_spec.rb
Expand Up @@ -44,6 +44,8 @@

it_behaves_like 'support be_installed.by(gem) matcher', 'jekyll'
it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
it_behaves_like 'support be_installed.by(npm) matcher', 'bower'
it_behaves_like 'support be_installed.by(npm).with_version matcher', 'bower', '0.9.2'

it_behaves_like 'support belong_to_group matcher', 'root', 'root'
it_behaves_like 'support have_gid matcher', 'root', 0
Expand Down
2 changes: 2 additions & 0 deletions spec/solaris/package_spec.rb
Expand Up @@ -6,4 +6,6 @@
it_behaves_like 'support package installed matcher', 'httpd'
it_behaves_like 'support package installed by gem matcher', 'jekyll'
it_behaves_like 'support package installed by gem with version matcher', 'jekyll', '1.1.1'
it_behaves_like 'support package installed by npm matcher', 'bower'
it_behaves_like 'support package installed by npm with version matcher', 'bower', '0.9.2'
end
10 changes: 10 additions & 0 deletions spec/support/shared_commands_examples.rb
Expand Up @@ -8,6 +8,16 @@
it { should eq "gem list --local | grep -w -- ^#{package} | grep -w -- ^#{version}" }
end

shared_examples_for 'support command check_installed_by_npm' do |package|
subject { commands.check_installed_by_npm(package) }
it { should eq "npm ls #{package} -g" }
end

shared_examples_for 'support command check_installed_by_npm with_version' do |package, version|
subject { commands.check_installed_by_npm(package) }
it { should eq "npm ls #{package} -g | grep -w -- #{version}" }
end

shared_examples_for 'support command check_file' do |file|
subject { commands.check_file(file) }
it { should eq "test -f #{file}" }
Expand Down
24 changes: 24 additions & 0 deletions spec/support/shared_matcher_examples.rb
Expand Up @@ -653,6 +653,30 @@
end
end

shared_examples_for 'support be_installed.by(npm) matcher' do |name|
describe 'be_installed.by(npm)' do
describe name do
it { should be_installed.by('npm') }
end

describe 'invalid-npm' do
it { should_not be_installed.by('npm') }
end
end
end

shared_examples_for 'support be_installed.by(npm).with_version matcher' do |name, version|
describe 'be_installed.by(npm).with_version' do
describe name do
it { should be_installed.by('npm').with_version(version) }
end

describe name do
it { should_not be_installed.by('npm').with_version('invalid-version') }
end
end
end

shared_examples_for 'support belong_to_group matcher' do |user, group|
describe 'belong_to_group' do
describe user do
Expand Down
24 changes: 24 additions & 0 deletions spec/support/shared_package_examples.rb
Expand Up @@ -33,3 +33,27 @@
end
end
end

shared_examples_for 'support package installed by npm matcher' do |name|
describe 'installed by npm' do
describe package(name) do
it { should be_installed.by('npm') }
end

describe 'invalid-npm' do
it { should_not be_installed.by('npm') }
end
end
end

shared_examples_for 'support package installed by npm with version matcher' do |name, version|
describe 'installed by npm with version' do
describe package(name) do
it { should be_installed.by('npm').with_version(version) }
end

describe package(name) do
it { should_not be_installed.by('npm').with_version('invalid-version') }
end
end
end

0 comments on commit 9a75a97

Please sign in to comment.