diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index 8b9285f..4170af9 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "foreman/cli" -describe "Foreman::CLI" do +describe "Foreman::CLI", :fakefs do subject { Foreman::CLI.new } describe "start" do @@ -89,47 +89,47 @@ describe "Foreman::CLI" do end end end - + describe "run" do describe "with a valid Procfile" do before { write_procfile } describe "and a command" do let(:command) { ["ls", "-l"] } - + before(:each) do stub(subject).exec end - + it "should load the environment file" do write_env preserving_env do subject.run *command ENV["FOO"].should == "bar" end - + ENV["FOO"].should be_nil end - + it "should runute the command as a string" do mock(subject).exec(command.join(" ")) subject.run *command end end - + describe "and a non-existent command" do let(:command) { "iuhtngrglhulhdfg" } - + it "should print an error" do mock_error(subject, "command not found: #{command}") do subject.run command end end end - + describe "and a non-executable command" do let(:command) { __FILE__ } - + it "should print an error" do mock_error(subject, "not executable: #{command}") do subject.run command diff --git a/spec/foreman/engine_spec.rb b/spec/foreman/engine_spec.rb index d7d42ee..3b416b5 100644 --- a/spec/foreman/engine_spec.rb +++ b/spec/foreman/engine_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "foreman/engine" -describe "Foreman::Engine" do +describe "Foreman::Engine", :fakefs do subject { Foreman::Engine.new("Procfile", {}) } describe "initialize" do diff --git a/spec/foreman/export/bluepill_spec.rb b/spec/foreman/export/bluepill_spec.rb index 89c0071..5d2eefa 100644 --- a/spec/foreman/export/bluepill_spec.rb +++ b/spec/foreman/export/bluepill_spec.rb @@ -3,7 +3,7 @@ require "foreman/engine" require "foreman/export/bluepill" require "tmpdir" -describe Foreman::Export::Bluepill do +describe Foreman::Export::Bluepill, :fakefs do let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") } let(:engine) { Foreman::Engine.new(procfile) } let(:bluepill) { Foreman::Export::Bluepill.new(engine) } @@ -18,7 +18,7 @@ describe Foreman::Export::Bluepill do it "exports to the filesystem with concurrency" do bluepill.export("/tmp/init", :concurrency => "alpha=2") - + normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app-concurrency.pill")) end -end \ No newline at end of file +end diff --git a/spec/foreman/export/runit_spec.rb b/spec/foreman/export/runit_spec.rb index d42fb5c..3b5f48f 100644 --- a/spec/foreman/export/runit_spec.rb +++ b/spec/foreman/export/runit_spec.rb @@ -3,34 +3,34 @@ require "foreman/engine" require "foreman/export/runit" require "tmpdir" -describe Foreman::Export::Runit do +describe Foreman::Export::Runit, :fakefs do let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile", 'bar=baz') } let(:engine) { Foreman::Engine.new(procfile) } let(:runit) { Foreman::Export::Runit.new(engine) } - + before(:each) { load_export_templates_into_fakefs("runit") } before(:each) { stub(runit).say } before(:each) { stub(FakeFS::FileUtils).chmod } - + it "exports to the filesystem" do FileUtils.mkdir_p('/tmp/init') runit.export('/tmp/init', :concurrency => "alpha=2,bravo=1") - + File.read("/tmp/init/app-alpha-1/run").should == example_export_file('runit/app-alpha-1-run') - File.read("/tmp/init/app-alpha-1/log/run").should == + File.read("/tmp/init/app-alpha-1/log/run").should == example_export_file('runit/app-alpha-1-log-run') File.read("/tmp/init/app-alpha-1/env/PORT").should == "5000\n" File.read("/tmp/init/app-alpha-1/env/BAR").should == "baz\n" - + File.read("/tmp/init/app-alpha-2/run").should == example_export_file('runit/app-alpha-2-run') - File.read("/tmp/init/app-alpha-2/log/run").should == + File.read("/tmp/init/app-alpha-2/log/run").should == example_export_file('runit/app-alpha-2-log-run') File.read("/tmp/init/app-alpha-2/env/PORT").should == "5001\n" File.read("/tmp/init/app-alpha-2/env/BAR").should == "baz\n" - + File.read("/tmp/init/app-bravo-1/run").should == example_export_file('runit/app-bravo-1-run') - File.read("/tmp/init/app-bravo-1/log/run").should == + File.read("/tmp/init/app-bravo-1/log/run").should == example_export_file('runit/app-bravo-1-log-run') File.read("/tmp/init/app-bravo-1/env/PORT").should == "5100\n" end -end \ No newline at end of file +end diff --git a/spec/foreman/export/upstart_spec.rb b/spec/foreman/export/upstart_spec.rb index bc582b4..39881ca 100644 --- a/spec/foreman/export/upstart_spec.rb +++ b/spec/foreman/export/upstart_spec.rb @@ -3,7 +3,7 @@ require "foreman/engine" require "foreman/export/upstart" require "tmpdir" -describe Foreman::Export::Upstart do +describe Foreman::Export::Upstart, :fakefs do let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") } let(:engine) { Foreman::Engine.new(procfile) } let(:upstart) { Foreman::Export::Upstart.new(engine) } diff --git a/spec/foreman_spec.rb b/spec/foreman_spec.rb index ef1bbb3..dfd0fbc 100644 --- a/spec/foreman_spec.rb +++ b/spec/foreman_spec.rb @@ -8,13 +8,8 @@ describe Foreman do it { should be_a String } end - describe "::load_env!(env_file)" do - before do - FakeFS.activate! - end - + describe "::load_env!(env_file)", :fakefs do after do - FakeFS.deactivate! ENV['FOO'] = nil end @@ -22,7 +17,7 @@ describe Foreman do File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") } Foreman.load_env!("/tmp/env1") ENV['FOO'].should == 'bar' - end + end it "should assume env_file in ./.env" do File.open("./.env", "w") { |f| f.puts("FOO=bar") } diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 6fd5efe..a6aaece 100644 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -3,16 +3,16 @@ require "spec_helper" describe "spec helpers" do describe "#preserving_env" do after { ENV.delete "FOO" } - + it "should remove added environment vars" do preserving_env { ENV["FOO"] = "baz" } ENV["FOO"].should == nil end - + it "should reset modified environment vars" do ENV["FOO"] = "bar" preserving_env { ENV["FOO"] = "baz"} ENV["FOO"].should == "bar" end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1803f4a..1f2f637 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -76,10 +76,11 @@ end def normalize_space(s) s.gsub(/\n[\n\s]*/, "\n") end - + RSpec.configure do |config| + config.treat_symbols_as_metadata_keys_with_true_values = true config.color_enabled = true config.order = 'rand' - config.include FakeFS::SpecHelpers + config.include FakeFS::SpecHelpers, :fakefs config.mock_with :rr end