Skip to content

Commit

Permalink
Switch to new RSpec expect syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudgg committed Sep 18, 2013
1 parent 2bad5ad commit 14c4886
Show file tree
Hide file tree
Showing 43 changed files with 785 additions and 782 deletions.
46 changes: 23 additions & 23 deletions spec/guard/cli_spec.rb
Expand Up @@ -10,7 +10,7 @@
before { Guard.stub(:start) }

it 'delegates to Guard.start' do
Guard.should_receive(:start)
expect(Guard).to receive(:start)

subject.start
end
Expand All @@ -29,7 +29,7 @@
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }

it 'does not show the Bundler warning' do
Guard::UI.should_not_receive(:info).with(/Guard here!/)
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.start
end
end
Expand All @@ -43,12 +43,12 @@
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }

it 'does show the Bundler warning' do
Guard::UI.should_receive(:info).with(/Guard here!/)
expect(Guard::UI).to receive(:info).with(/Guard here!/)
subject.start
end

it 'does not show the Bundler warning with the :no_bundler_warning flag' do
Guard::UI.should_not_receive(:info).with(/Guard here!/)
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.options = { no_bundler_warning: true }
subject.start
end
Expand All @@ -57,41 +57,41 @@

context 'without a Gemfile in the project dir' do
before do
File.should_receive(:exists?).with('Gemfile').and_return false
expect(File).to receive(:exists?).with('Gemfile').and_return false
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end

after { ENV['BUNDLE_GEMFILE'] = @bundler_env }

it 'does not show the Bundler warning' do
Guard::UI.should_not_receive(:info).with(/Guard here!/)
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.start
end
end
end

describe '#list' do
it 'outputs the Guard plugins list' do
::Guard::DslDescriber.should_receive(:new) { dsl_describer }
dsl_describer.should_receive(:list)
expect(::Guard::DslDescriber).to receive(:new) { dsl_describer }
expect(dsl_describer).to receive(:list)

subject.list
end
end

describe '#notifiers' do
it 'outputs the notifiers list' do
::Guard::DslDescriber.should_receive(:new) { dsl_describer }
dsl_describer.should_receive(:notifiers)
expect(::Guard::DslDescriber).to receive(:new) { dsl_describer }
expect(dsl_describer).to receive(:notifiers)

subject.notifiers
end
end

describe '#version' do
it 'shows the current version' do
subject.should_receive(:puts).with(/#{ ::Guard::VERSION }/)
expect(subject).to receive(:puts).with(/#{ ::Guard::VERSION }/)

subject.version
end
Expand All @@ -107,27 +107,27 @@
end

it 'creates a Guardfile by delegating to Guardfile.create_guardfile' do
Guard::Guardfile.should_receive(:create_guardfile).with(abort_on_existence: options[:bare])
expect(Guard::Guardfile).to receive(:create_guardfile).with(abort_on_existence: options[:bare])

subject.init
end

it 'initializes the templates of all installed Guards by delegating to Guardfile.initialize_all_templates' do
Guard::Guardfile.should_receive(:initialize_all_templates)
expect(Guard::Guardfile).to receive(:initialize_all_templates)

subject.init
end

it 'initializes each passed template by delegating to Guardfile.initialize_template' do
Guard::Guardfile.should_receive(:initialize_template).with('rspec')
Guard::Guardfile.should_receive(:initialize_template).with('pow')
expect(Guard::Guardfile).to receive(:initialize_template).with('rspec')
expect(Guard::Guardfile).to receive(:initialize_template).with('pow')

subject.init 'rspec','pow'
end

context 'when passed a guard name' do
it 'initializes the template of the passed Guard by delegating to Guardfile.initialize_template' do
Guard::Guardfile.should_receive(:initialize_template).with('rspec')
expect(Guard::Guardfile).to receive(:initialize_template).with('rspec')

subject.init 'rspec'
end
Expand All @@ -137,9 +137,9 @@
let(:options) { {bare: true} }

it 'Only creates the Guardfile and does not initialize any Guard template' do
Guard::Guardfile.should_receive(:create_guardfile)
Guard::Guardfile.should_not_receive(:initialize_template)
Guard::Guardfile.should_not_receive(:initialize_all_templates)
expect(Guard::Guardfile).to receive(:create_guardfile)
expect(Guard::Guardfile).to_not receive(:initialize_template)
expect(Guard::Guardfile).to_not receive(:initialize_all_templates)

subject.init
end
Expand All @@ -154,7 +154,7 @@
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }

it 'does not show the Bundler warning' do
Guard::UI.should_not_receive(:info).with(/Guard here!/)
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)

subject.init
end
Expand All @@ -169,7 +169,7 @@
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }

it 'does not show the Bundler warning' do
Guard::UI.should_receive(:info).with(/Guard here!/)
expect(Guard::UI).to receive(:info).with(/Guard here!/)

subject.init
end
Expand All @@ -178,8 +178,8 @@

describe '#show' do
it 'outputs the Guard::DslDescriber.list result' do
::Guard::DslDescriber.should_receive(:new) { dsl_describer }
dsl_describer.should_receive(:show)
expect(::Guard::DslDescriber).to receive(:new) { dsl_describer }
expect(dsl_describer).to receive(:show)

subject.show
end
Expand Down
46 changes: 23 additions & 23 deletions spec/guard/commander_spec.rb
Expand Up @@ -15,27 +15,27 @@
before { ::Guard.stub(:running) { false } }

it "setup Guard" do
::Guard.should_receive(:setup).with(foo: 'bar')
expect(::Guard).to receive(:setup).with(foo: 'bar')

::Guard.start(foo: 'bar')
end
end

it "displays an info message" do
::Guard.instance_variable_set('@watchdirs', ['/foo/bar'])
::Guard::UI.should_receive(:info).with("Guard is now watching at '/foo/bar'")
expect(::Guard::UI).to receive(:info).with("Guard is now watching at '/foo/bar'")

::Guard.start
end

it "tell the runner to run the :start task" do
::Guard.runner.should_receive(:run).with(:start)
expect(::Guard.runner).to receive(:run).with(:start)

::Guard.start
end

it "start the listener" do
::Guard.listener.should_receive(:start)
expect(::Guard.listener).to receive(:start)

::Guard.start
end
Expand All @@ -53,34 +53,34 @@
before { ::Guard.stub(:running) { false } }

it "setup Guard" do
::Guard.should_receive(:setup)
expect(::Guard).to receive(:setup)

::Guard.stop
end
end

it "turns the notifier off" do
::Guard::Notifier.should_receive(:turn_off)
expect(::Guard::Notifier).to receive(:turn_off)

::Guard.stop
end

it "tell the runner to run the :stop task" do
::Guard.runner.should_receive(:run).with(:stop)
expect(::Guard.runner).to receive(:run).with(:stop)

::Guard.stop
end

it "stops the listener" do
::Guard.listener.should_receive(:stop)
expect(::Guard.listener).to receive(:stop)

::Guard.stop
end

it "sets the running state to false" do
::Guard.running = true
::Guard.stop
::Guard.running.should be_false
expect(::Guard.running).to be_false
end
end

Expand All @@ -100,27 +100,27 @@
before { ::Guard.stub(:running) { false } }

it "setup Guard" do
::Guard.should_receive(:setup)
expect(::Guard).to receive(:setup)

::Guard.reload
end
end

it 'clears the screen' do
::Guard::UI.should_receive(:clear)
expect(::Guard::UI).to receive(:clear)

subject.reload
end

context 'with a given scope' do
it 'does not re-evaluate the Guardfile' do
Guard::Guardfile::Evaluator.any_instance.should_not_receive(:reevaluate_guardfile)
::Guard::Guardfile::Evaluator.any_instance.should_not_receive(:reevaluate_guardfile)

subject.reload({ groups: [group] })
end

it 'reloads Guard' do
runner.should_receive(:run).with(:reload, { groups: [group] })
expect(runner).to receive(:run).with(:reload, { groups: [group] })

subject.reload({ groups: [group] })
end
Expand All @@ -134,7 +134,7 @@
end

it 'does not reload Guard' do
runner.should_not_receive(:run).with(:reload, {})
expect(runner).to_not receive(:run).with(:reload, {})

subject.reload
end
Expand All @@ -157,23 +157,23 @@
before { ::Guard.stub(:running) { false } }

it "setup Guard" do
::Guard.should_receive(:setup)
expect(::Guard).to receive(:setup)

::Guard.run_all
end
end

context 'with a given scope' do
it 'runs all with the scope' do
runner.should_receive(:run).with(:run_all, { groups: [group] })
expect(runner).to receive(:run).with(:run_all, { groups: [group] })

subject.run_all({ groups: [group] })
end
end

context 'with an empty scope' do
it 'runs all' do
runner.should_receive(:run).with(:run_all, {})
expect(runner).to receive(:run).with(:run_all, {})

subject.run_all
end
Expand All @@ -185,20 +185,20 @@
before { subject.interactor = double('interactor').as_null_object }

it 'disallows running the block concurrently to avoid inconsistent states' do
subject.lock.should_receive(:synchronize)
expect(subject.lock).to receive(:synchronize)
subject.within_preserved_state &Proc.new {}
end

it 'runs the passed block' do
@called = false
subject.within_preserved_state { @called = true }
@called.should be_true
expect(@called).to be_true
end

context '@running is true' do
it 'stops the interactor before running the block and starts it again when done' do
subject.interactor.should_receive(:stop)
subject.interactor.should_receive(:start)
expect(subject.interactor).to receive(:stop)
expect(subject.interactor).to receive(:start)
subject.within_preserved_state &Proc.new {}
end
end
Expand All @@ -207,8 +207,8 @@
before { ::Guard.stub(:running) { false } }

it 'stops the interactor before running the block and do not starts it again when done' do
subject.interactor.should_receive(:stop)
subject.interactor.should_not_receive(:start)
expect(subject.interactor).to receive(:stop)
expect(subject.interactor).to_not receive(:start)
subject.within_preserved_state &Proc.new {}
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/guard/commands/all_spec.rb
Expand Up @@ -17,28 +17,28 @@
describe '#perform' do
context 'without scope' do
it 'runs the :run_all action' do
Guard.should_receive(:run_all).with(groups: [], plugins: [])
expect(Guard).to receive(:run_all).with(groups: [], plugins: [])
Pry.run_command 'all'
end
end

context 'with a valid Guard group scope' do
it 'runs the :run_all action with the given scope' do
Guard.should_receive(:run_all).with(groups: [foo_group], plugins: [])
expect(Guard).to receive(:run_all).with(groups: [foo_group], plugins: [])
Pry.run_command 'all foo'
end
end

context 'with a valid Guard plugin scope' do
it 'runs the :run_all action with the given scope' do
Guard.should_receive(:run_all).with(plugins: [bar_guard], groups: [])
expect(Guard).to receive(:run_all).with(plugins: [bar_guard], groups: [])
Pry.run_command 'all bar'
end
end

context 'with an invalid scope' do
it 'does not run the action' do
Guard.should_not_receive(:run_all)
expect(Guard).to_not receive(:run_all)
Pry.run_command 'all baz'
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/guard/commands/change_spec.rb
Expand Up @@ -11,21 +11,21 @@
describe '#perform' do
context 'with a file' do
it 'runs the :run_on_changes action with the given scope' do
::Guard.runner.should_receive(:run_on_changes).with(['foo'], [], [])
expect(::Guard.runner).to receive(:run_on_changes).with(['foo'], [], [])
Pry.run_command 'change foo'
end
end

context 'with multiple files' do
it 'runs the :run_on_changes action with the given scope' do
::Guard.runner.should_receive(:run_on_changes).with(['foo', 'bar', 'baz'], [], [])
expect(::Guard.runner).to receive(:run_on_changes).with(['foo', 'bar', 'baz'], [], [])
Pry.run_command 'change foo bar baz'
end
end

context 'without a file' do
it 'does not run the :run_on_changes action' do
::Guard.runner.should_not_receive(:run_on_changes)
expect(::Guard.runner).to_not receive(:run_on_changes)
Pry.run_command 'change'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/guard/commands/notification_spec.rb
Expand Up @@ -8,7 +8,7 @@

describe '#perform' do
it 'toggles the Guard notifier' do
::Guard::Notifier.should_receive(:toggle)
expect(::Guard::Notifier).to receive(:toggle)
Pry.run_command 'notification'
end
end
Expand Down

0 comments on commit 14c4886

Please sign in to comment.