Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Lcg/rspec 3 #99

Merged
merged 3 commits into from
Jul 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
-fs
-f documentation
3 changes: 1 addition & 2 deletions chef-dk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Gem::Specification.new do |gem|
gem.add_dependency "cookbook-omnifetch", "~> 0.0"

%w(rspec-core rspec-expectations rspec-mocks).each do |dev_gem|
gem.add_development_dependency dev_gem, "~> 2.14.0"
gem.add_development_dependency dev_gem, "~> 3.0"
end
gem.add_development_dependency "pry-debugger"
end
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

require 'rubygems'
require 'rspec/mocks'
require 'pry-debugger'
require 'test_helpers'

RSpec.configure do |c|
Expand All @@ -28,5 +27,4 @@

c.filter_run :focus => true
c.run_all_when_everything_filtered = true
c.treat_symbols_as_metadata_keys_with_true_values = true
end
10 changes: 5 additions & 5 deletions spec/unit/chef_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@

subject(:chef_runner) do
r = ChefDK::ChefRunner.new(default_cookbook_path, run_list)
r.stub(:stdout).and_return(stdout_io)
r.stub(:stderr).and_return(stderr_io)
allow(r).to receive(:stdout).and_return(stdout_io)
allow(r).to receive(:stderr).and_return(stderr_io)
r
end

it "sets up Chef::Config" do
chef_runner.configure
expect(Chef::Config.solo).to be_true
expect(Chef::Config.solo).to be true
expect(Chef::Config.cookbook_path).to eq(default_cookbook_path)
expect(Chef::Config.color).to be_true
expect(Chef::Config.diff_disabled).to be_true
expect(Chef::Config.color).to be true
expect(Chef::Config.diff_disabled).to be true
end

it "configures a formatter for the chef run" do
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def stderr
let(:version_message) { "Chef Development Kit Version: #{ChefDK::VERSION}\n" }

def run_cli(expected_exit_code)
cli.should_receive(:exit).with(expected_exit_code)
expect(cli).to receive(:exit).with(expected_exit_code)
cli.run
end

subject(:cli) do
ChefDK::CLI.new(argv).tap do |c|
c.stub(:commands_map).and_return(commands_map)
c.stub(:stdout).and_return(stdout_io)
c.stub(:stderr).and_return(stderr_io)
allow(c).to receive(:commands_map).and_return(commands_map)
allow(c).to receive(:stdout).and_return(stdout_io)
allow(c).to receive(:stderr).and_return(stderr_io)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/command/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def stdout
end

before do
command_instance.stub(:stdout).and_return(stdout_io)
allow(command_instance).to receive(:stdout).and_return(stdout_io)
end


Expand Down
18 changes: 9 additions & 9 deletions spec/unit/command/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ def run_command

describe "when locating omnibus directory" do
it "should find omnibus bin directory from ruby path" do
Gem.stub(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
expect(command_instance.omnibus_bin_dir).to include("eg_omnibus_dir/valid/bin")
end

it "should find omnibus embedded bin directory from ruby path" do
Gem.stub(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
expect(command_instance.omnibus_embedded_bin_dir).to include("eg_omnibus_dir/valid/embedded/bin")
end

it "should raise OmnibusInstallNotFound if directory is not looking like omnibus" do
Gem.stub(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
expect{command_instance.omnibus_bin_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
end

it "should raise OmnibusInstallNotFound if directory is not looking like omnibus" do
Gem.stub(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
expect{command_instance.omnibus_embedded_bin_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
end
end
Expand All @@ -57,7 +57,7 @@ def run_command
let(:ruby_path) { File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby") }

before do
Gem.stub(:ruby).and_return(ruby_path)
allow(Gem).to receive(:ruby).and_return(ruby_path)
end

context "when running exec env" do
Expand All @@ -79,8 +79,8 @@ def run_command
end

before do
command_instance.stub(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
command_instance.stub(:omnibus_bin_dir).and_return(omnibus_bin_dir)
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
end

it "should call exec to fire off the command with the correct environment" do
Expand Down Expand Up @@ -108,8 +108,8 @@ def run_command
end

before do
command_instance.stub(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
command_instance.stub(:omnibus_bin_dir).and_return(omnibus_bin_dir)
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
end

it "should raise Errno::ENOENT" do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/command/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def stdout

subject(:generate) do
g = generator_class.new
g.stub(:stdout).and_return(stdout_io)
g.stub(:stderr).and_return(stderr_io)
allow(g).to receive(:stdout).and_return(stdout_io)
allow(g).to receive(:stderr).and_return(stderr_io)
g
end

Expand All @@ -68,7 +68,7 @@ def stdout
end

it "includes the generator in the list" do
expect(generator_class).to have(1).generators
expect(generator_class.generators.size).to eq(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could bring in the rspec-collections gem. I kinda like the fancy syntax but it's maybe a bit over-magical so I'm not inclined to argue for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I kind of assumed they might have done that for a reason like pulling out 'its' because its not really a good idea, but didn't quite have the motivation to google up the bikeshed...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, google doesn't turn up much other than criticism of them being "magical" and "poorly understood" but it seems easy enough for me to understand... I'm agnostic...

generator_spec = generator_class.generators.first
expect(generator_spec.name).to eq(:example)
expect(generator_spec.class_name).to eq(:Example)
Expand Down
28 changes: 14 additions & 14 deletions spec/unit/command/generator_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def generator_context
describe "generated files" do
it "creates a new cookbook" do
Dir.chdir(tempdir) do
cookbook_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
cookbook_generator.run
end
generated_files = Dir.glob(File.join(tempdir, "new_app", "**", "*"), File::FNM_DOTMATCH)
Expand All @@ -84,13 +84,13 @@ def generator_context
shared_examples_for "a generated file" do |context_var|
before do
Dir.chdir(tempdir) do
cookbook_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
cookbook_generator.run
end
end

it "should contain #{context_var} from the generator context" do
File.read(file).should match line
expect(File.read(file)).to match line
end
end

Expand Down Expand Up @@ -159,7 +159,7 @@ def generator_context

subject(:cookbook_generator) do
g = described_class.new(argv)
g.stub(:cookbook_path_in_git_repo?).and_return(false)
allow(g).to receive(:cookbook_path_in_git_repo?).and_return(false)
g
end

Expand All @@ -185,8 +185,8 @@ def generator_context

def with_argv(argv)
generator = described_class.new(argv)
generator.stub(:stdout).and_return(stdout_io)
generator.stub(:stderr).and_return(stderr_io)
allow(generator).to receive(:stdout).and_return(stdout_io)
allow(generator).to receive(:stderr).and_return(stderr_io)
generator
end

Expand Down Expand Up @@ -214,7 +214,7 @@ def with_argv(argv)

it "creates a new cookbook" do
Dir.chdir(tempdir) do
cookbook_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
cookbook_generator.run
end
generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
Expand All @@ -226,13 +226,13 @@ def with_argv(argv)
shared_examples_for "a generated file" do |context_var|
before do
Dir.chdir(tempdir) do
cookbook_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
cookbook_generator.run
end
end

it "should contain #{context_var} from the generator context" do
File.read(file).should match line
expect(File.read(file)).to match line
end
end

Expand Down Expand Up @@ -304,7 +304,7 @@ def with_argv(argv)

it "creates a new cookbook" do
Dir.chdir(tempdir) do
cookbook_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
cookbook_generator.run
end
generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
Expand Down Expand Up @@ -336,8 +336,8 @@ def stderr

subject(:recipe_generator) do
generator = described_class.new(argv)
generator.stub(:stdout).and_return(stdout_io)
generator.stub(:stderr).and_return(stderr_io)
allow(generator).to receive(:stdout).and_return(stdout_io)
allow(generator).to receive(:stderr).and_return(stderr_io)
generator
end

Expand Down Expand Up @@ -382,7 +382,7 @@ def generator_context

it "creates a new recipe" do
Dir.chdir(cookbook_path) do
recipe_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(recipe_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
recipe_generator.run
end

Expand Down Expand Up @@ -424,7 +424,7 @@ def generator_context
end

it "creates a new recipe" do
recipe_generator.chef_runner.stub(:stdout).and_return(stdout_io)
allow(recipe_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
recipe_generator.run

generated_files.each do |expected_file|
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/command/shell_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

let(:command_instance) do
ChefDK::Command::ShellInit.new.tap do |c|
c.stub(:stdout).and_return(stdout_io)
c.stub(:stderr).and_return(stderr_io)
allow(c).to receive(:stdout).and_return(stdout_io)
allow(c).to receive(:stderr).and_return(stderr_io)
end
end

Expand Down Expand Up @@ -57,8 +57,8 @@
let(:omnibus_embedded_bin_dir) { "/foo/embedded/bin" }

before do
command_instance.stub(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
command_instance.stub(:omnibus_bin_dir).and_return(omnibus_bin_dir)
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
end

it "emits a script to add ChefDK's ruby to the shell environment" do
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/command/verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ def run_command(expected_exit_code)

describe "when locating omnibus directory" do
it "should find omnibus app directory from ruby path" do
Gem.stub(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
expect(command_instance.omnibus_apps_dir).to include("eg_omnibus_dir/valid/embedded")
end

it "should raise OmnibusInstallNotFound if directory is not looking like omnibus" do
Gem.stub(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
expect{command_instance.omnibus_apps_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
end

it "raises OmnibusInstallNotFound if omnibus directory doesn't exist" do
Gem.stub(:ruby).and_return(File.join(fixtures_path,"eg_omnibus_dir/missing_apps/embedded/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,"eg_omnibus_dir/missing_apps/embedded/bin/ruby"))
expect{command_instance.omnibus_apps_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
end

it "raises MissingComponentError when a component doesn't exist" do
Gem.stub(:ruby).and_return(File.join(fixtures_path,"eg_omnibus_dir/missing_component/embedded/bin/ruby"))
allow(Gem).to receive(:ruby).and_return(File.join(fixtures_path,"eg_omnibus_dir/missing_component/embedded/bin/ruby"))
expect{command_instance.validate_components!}.to raise_error(ChefDK::MissingComponentError)
end
end
Expand Down Expand Up @@ -133,9 +133,9 @@ def stdout
end

before do
Gem.stub(:ruby).and_return(ruby_path)
command_instance.stub(:stdout).and_return(stdout_io)
command_instance.stub(:components).and_return(components)
allow(Gem).to receive(:ruby).and_return(ruby_path)
allow(command_instance).to receive(:stdout).and_return(stdout_io)
allow(command_instance).to receive(:components).and_return(components)
end

context "when running smoke tests only" do
Expand Down Expand Up @@ -268,7 +268,7 @@ def stdout
it "should report the output of the first verification first" do
index_first = stdout.index("you are good to go...")
index_second = stdout.index("my friend everything is good...")
expect(index_second > index_first).to be_true
expect(index_second > index_first).to be true
end

context "and components are filtered by CLI args" do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/commands_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

it "defines a subcommand mapping" do
expect(mapping.have_command?("example")).to be_true
expect(mapping.have_command?("example")).to be true
end

it "infers a non-hypenated command's require path" do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/component_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@

it "defines a unit test block" do
component.run_unit_test
expect(result[:unit_test]).to be_true
expect(result[:unit_test]).to be true
end

it "defines an integration test block" do
component.run_integration_test
expect(result[:integration_test]).to be_true
expect(result[:integration_test]).to be true
end

it "defines a smoke test block" do
component.run_smoke_test
expect(result[:smoke_test]).to be_true
expect(result[:smoke_test]).to be true
end

end
Expand Down
Loading