Skip to content

Commit

Permalink
Port to rspec 3
Browse files Browse the repository at this point in the history
Also migrate all usage of `rr` to rspec mocks, so `rr` is not needed to
run tests anymore.
  • Loading branch information
terceiro committed Nov 2, 2016
1 parent eab2e9c commit d65e861
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 84 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -5,8 +5,7 @@ gemspec
group :test do
gem 'rake'
gem 'fakefs', '~> 0.4.0'
gem 'rr', '~> 1.0.2'
gem 'rspec', '~> 2.99.0'
gem 'rspec', '~> 3.5'
gem "simplecov", :require => false
gem 'timecop'
gem "codeclimate-test-reporter", :require => false
Expand Down
25 changes: 14 additions & 11 deletions Gemfile.lock
Expand Up @@ -31,15 +31,19 @@ GEM
hpricot (>= 0.8.2)
mustache (>= 0.7.0)
rdiscount (>= 1.5.8)
rr (1.0.5)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.4)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
simplecov (0.11.2)
docile (~> 1.1.0)
json (~> 1.8)
Expand All @@ -62,8 +66,7 @@ DEPENDENCIES
foreman!
rake
ronn
rr (~> 1.0.2)
rspec (~> 2.99.0)
rspec (~> 3.5)
simplecov
timecop
yard
Expand Down
2 changes: 1 addition & 1 deletion spec/foreman/cli_spec.rb
Expand Up @@ -21,7 +21,7 @@
describe "when a Procfile doesnt exist", :fakefs do
it "displays an error" do
mock_error(subject, "Procfile does not exist.") do
dont_allow.instance_of(Foreman::Engine).start
expect_any_instance_of(Foreman::Engine).to_not receive(:start)
subject.start
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/foreman/engine_spec.rb
Expand Up @@ -35,19 +35,19 @@ def shutdown

describe "start" do
it "forks the processes" do
mock(subject.process("alpha")).run(anything)
mock(subject.process("bravo")).run(anything)
mock(subject).watch_for_output
mock(subject).wait_for_shutdown_or_child_termination
expect(subject.process("alpha")).to receive(:run)
expect(subject.process("bravo")).to receive(:run)
expect(subject).to receive(:watch_for_output)
expect(subject).to receive(:wait_for_shutdown_or_child_termination)
subject.start
end

it "handles concurrency" do
subject.options[:formation] = "alpha=2"
mock(subject.process("alpha")).run(anything).twice
mock(subject.process("bravo")).run(anything).never
mock(subject).watch_for_output
mock(subject).wait_for_shutdown_or_child_termination
expect(subject.process("alpha")).to receive(:run).twice
expect(subject.process("bravo")).to_not receive(:run)
expect(subject).to receive(:watch_for_output)
expect(subject).to receive(:wait_for_shutdown_or_child_termination)
subject.start
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/foreman/export/base_spec.rb
Expand Up @@ -9,7 +9,7 @@
let(:subject) { Foreman::Export::Base.new(location, engine) }

it "has a say method for displaying info" do
mock(subject).puts("[foreman export] foo")
expect(subject).to receive(:puts).with("[foreman export] foo")
subject.send(:say, "foo")
end

Expand Down
4 changes: 2 additions & 2 deletions spec/foreman/export/bluepill_spec.rb
Expand Up @@ -11,15 +11,15 @@
let(:bluepill) { Foreman::Export::Bluepill.new("/tmp/init", engine, options) }

before(:each) { load_export_templates_into_fakefs("bluepill") }
before(:each) { stub(bluepill).say }
before(:each) { allow(bluepill).to receive(:say) }

it "exports to the filesystem" do
bluepill.export
expect(normalize_space(File.read("/tmp/init/app.pill"))).to eq(normalize_space(example_export_file("bluepill/app.pill")))
end

it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.pill")
expect(FileUtils).to receive(:rm).with("/tmp/init/app.pill")

bluepill.export
bluepill.export
Expand Down
22 changes: 11 additions & 11 deletions spec/foreman/export/daemon_spec.rb
Expand Up @@ -11,7 +11,7 @@
let(:daemon) { Foreman::Export::Daemon.new("/tmp/init", engine, options) }

before(:each) { load_export_templates_into_fakefs("daemon") }
before(:each) { stub(daemon).say }
before(:each) { allow(daemon).to receive(:say) }

it "exports to the filesystem" do
daemon.export
Expand All @@ -24,15 +24,15 @@
end

it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.conf")
mock(FileUtils).rm("/tmp/init/app-alpha.conf")
mock(FileUtils).rm("/tmp/init/app-alpha-1.conf")
mock(FileUtils).rm("/tmp/init/app-bravo.conf")
mock(FileUtils).rm("/tmp/init/app-bravo-1.conf")
mock(FileUtils).rm("/tmp/init/app-foo-bar.conf")
mock(FileUtils).rm("/tmp/init/app-foo-bar-1.conf")
mock(FileUtils).rm("/tmp/init/app-foo_bar.conf")
mock(FileUtils).rm("/tmp/init/app-foo_bar-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar-1.conf")

daemon.export
daemon.export
Expand All @@ -44,7 +44,7 @@
["app2", "app2-alpha", "app2-alpha-1"].each do |name|
path = "/tmp/init/#{name}.conf"
FileUtils.touch(path)
dont_allow(FileUtils).rm(path)
expect(FileUtils).to_not receive(:rm).with(path)
end

daemon.export
Expand Down
4 changes: 2 additions & 2 deletions spec/foreman/export/inittab_spec.rb
Expand Up @@ -12,7 +12,7 @@
let(:inittab) { Foreman::Export::Inittab.new(location, engine, options) }

before(:each) { load_export_templates_into_fakefs("inittab") }
before(:each) { stub(inittab).say }
before(:each) { allow(inittab).to receive(:say) }

it "exports to the filesystem" do
inittab.export
Expand All @@ -23,7 +23,7 @@
let(:location) { "-" }

it "exports to stdout" do
mock(inittab).puts example_export_file("inittab/inittab.default")
expect(inittab).to receive(:puts).with(example_export_file("inittab/inittab.default"))
inittab.export
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/foreman/export/launchd_spec.rb
Expand Up @@ -10,7 +10,7 @@
let(:launchd) { Foreman::Export::Launchd.new("/tmp/init", engine, options) }

before(:each) { load_export_templates_into_fakefs("launchd") }
before(:each) { stub(launchd).say }
before(:each) { allow(launchd).to receive(:say) }

it "exports to the filesystem" do
launchd.export
Expand Down
4 changes: 2 additions & 2 deletions spec/foreman/export/runit_spec.rb
Expand Up @@ -10,8 +10,8 @@
let(:runit) { Foreman::Export::Runit.new('/tmp/init', engine, options) }

before(:each) { load_export_templates_into_fakefs("runit") }
before(:each) { stub(runit).say }
before(:each) { stub(FakeFS::FileUtils).chmod }
before(:each) { allow(runit).to receive(:say) }
before(:each) { allow(FakeFS::FileUtils).to receive(:chmod) }

it "exports to the filesystem" do
engine.env["BAR"] = "baz"
Expand Down
4 changes: 2 additions & 2 deletions spec/foreman/export/supervisord_spec.rb
Expand Up @@ -11,7 +11,7 @@
let(:supervisord) { Foreman::Export::Supervisord.new("/tmp/init", engine, options) }

before(:each) { load_export_templates_into_fakefs("supervisord") }
before(:each) { stub(supervisord).say }
before(:each) { allow(supervisord).to receive(:say) }

it "exports to the filesystem" do
write_env(".env", "FOO"=>"bar", "URL"=>"http://example.com/api?foo=bar&baz=1")
Expand All @@ -21,7 +21,7 @@
end

it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app.conf")
supervisord.export
supervisord.export
end
Expand Down
44 changes: 22 additions & 22 deletions spec/foreman/export/systemd_spec.rb
Expand Up @@ -11,7 +11,7 @@
let(:systemd) { Foreman::Export::Systemd.new("/tmp/init", engine, options) }

before(:each) { load_export_templates_into_fakefs("systemd") }
before(:each) { stub(systemd).say }
before(:each) { allow(systemd).to receive(:say) }

it "exports to the filesystem" do
systemd.export
Expand All @@ -27,27 +27,27 @@
end

it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.target")

mock(FileUtils).rm("/tmp/init/app-alpha@.service")
mock(FileUtils).rm("/tmp/init/app-alpha.target")
mock(FileUtils).rm("/tmp/init/app-alpha.target.wants/app-alpha@5000.service")
mock(FileUtils).rm_r("/tmp/init/app-alpha.target.wants")

mock(FileUtils).rm("/tmp/init/app-bravo.target")
mock(FileUtils).rm("/tmp/init/app-bravo@.service")
mock(FileUtils).rm("/tmp/init/app-bravo.target.wants/app-bravo@5100.service")
mock(FileUtils).rm_r("/tmp/init/app-bravo.target.wants")

mock(FileUtils).rm("/tmp/init/app-foo_bar.target")
mock(FileUtils).rm("/tmp/init/app-foo_bar@.service")
mock(FileUtils).rm("/tmp/init/app-foo_bar.target.wants/app-foo_bar@5200.service")
mock(FileUtils).rm_r("/tmp/init/app-foo_bar.target.wants")

mock(FileUtils).rm("/tmp/init/app-foo-bar.target")
mock(FileUtils).rm("/tmp/init/app-foo-bar@.service")
mock(FileUtils).rm("/tmp/init/app-foo-bar.target.wants/app-foo-bar@5300.service")
mock(FileUtils).rm_r("/tmp/init/app-foo-bar.target.wants")
expect(FileUtils).to receive(:rm).with("/tmp/init/app.target")

expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha@.service")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.target")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.target.wants/app-alpha@5000.service")
expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-alpha.target.wants")

expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.target")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo@.service")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.target.wants/app-bravo@5100.service")
expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-bravo.target.wants")

expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.target")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar@.service")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.target.wants/app-foo_bar@5200.service")
expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-foo_bar.target.wants")

expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.target")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar@.service")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.target.wants/app-foo-bar@5300.service")
expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-foo-bar.target.wants")


systemd.export
Expand Down
24 changes: 12 additions & 12 deletions spec/foreman/export/upstart_spec.rb
Expand Up @@ -11,7 +11,7 @@
let(:upstart) { Foreman::Export::Upstart.new("/tmp/init", engine, options) }

before(:each) { load_export_templates_into_fakefs("upstart") }
before(:each) { stub(upstart).say }
before(:each) { allow(upstart).to receive(:say) }

it "exports to the filesystem" do
upstart.export
Expand All @@ -24,15 +24,15 @@
end

it "cleans up if exporting into an existing dir" do
mock(FileUtils).rm("/tmp/init/app.conf")
mock(FileUtils).rm("/tmp/init/app-alpha.conf")
mock(FileUtils).rm("/tmp/init/app-alpha-1.conf")
mock(FileUtils).rm("/tmp/init/app-bravo.conf")
mock(FileUtils).rm("/tmp/init/app-bravo-1.conf")
mock(FileUtils).rm("/tmp/init/app-foo-bar.conf")
mock(FileUtils).rm("/tmp/init/app-foo-bar-1.conf")
mock(FileUtils).rm("/tmp/init/app-foo_bar.conf")
mock(FileUtils).rm("/tmp/init/app-foo_bar-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar-1.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.conf")
expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar-1.conf")

upstart.export
upstart.export
Expand All @@ -44,7 +44,7 @@
["app2", "app2-alpha", "app2-alpha-1"].each do |name|
path = "/tmp/init/#{name}.conf"
FileUtils.touch(path)
dont_allow(FileUtils).rm(path)
expect(FileUtils).to_not receive(:rm).with(path)
end

upstart.export
Expand All @@ -56,7 +56,7 @@
["app-worker", "app-worker-worker", "app-worker-worker-1"].each do |name|
path = "/tmp/init/#{name}.conf"
FileUtils.touch(path)
dont_allow(FileUtils).rm(path)
expect(FileUtils).to_not receive(:rm).with(path)
end

upstart.export
Expand Down
2 changes: 1 addition & 1 deletion spec/foreman/export_spec.rb
Expand Up @@ -6,7 +6,7 @@

describe "with a formatter that doesn't declare the appropriate class" do
it "prints an error" do
mock(subject).require("foreman/export/invalidformatter")
expect(subject).to receive(:require).with("foreman/export/invalidformatter")
mock_export_error("Unknown export format: invalidformatter (no class Foreman::Export::Invalidformatter).") do
subject.formatter("invalidformatter")
end
Expand Down
4 changes: 2 additions & 2 deletions spec/foreman/process_spec.rb
Expand Up @@ -55,13 +55,13 @@ def run(process, options={})
end

it "can execute" do
mock(Kernel).exec "bin/command"
expect(Kernel).to receive(:exec).with("bin/command")
process = Foreman::Process.new("bin/command")
process.exec
end

it "can execute with env" do
mock(Kernel).exec "bin/command bar"
expect(Kernel).to receive(:exec).with("bin/command bar")
process = Foreman::Process.new("bin/command $FOO")
process.exec(:env => { "FOO" => "bar" })
end
Expand Down
2 changes: 1 addition & 1 deletion spec/foreman_spec.rb
Expand Up @@ -5,7 +5,7 @@

describe "VERSION" do
subject { Foreman::VERSION }
it { should be_a String }
it { is_expected.to be_a String }
end

describe "runner" do
Expand Down
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Expand Up @@ -19,7 +19,7 @@ def mock_export_error(message)

def mock_error(subject, message)
mock_exit do
mock(subject).puts("ERROR: #{message}")
expect(subject).to receive(:puts).with("ERROR: #{message}")
yield
end
end
Expand Down Expand Up @@ -166,11 +166,9 @@ def capture_stdout
end

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.color = true
config.order = 'rand'
config.include FakeFS::SpecHelpers, :fakefs
config.mock_with :rr
config.before(:each) do
FileUtils.mkdir_p('/tmp')
end
Expand Down

0 comments on commit d65e861

Please sign in to comment.