Permalink
Browse files

Update specs to reflect up-to-date RSpec usage

* Replace `should` syntax with `expect`, and enforce its usage
* Use implicit docstrings where possible
  • Loading branch information...
njonsson committed May 13, 2013
1 parent a60bae5 commit 5f2cf2fb314312993ea66c25d815a3dadad8f9a6
@@ -6,8 +6,8 @@
describe '-- when sent #slice with keys that are present and those that are not --' do
it 'should return the expected subset hash' do
- subject.slice(:baz, :fizzle, :quux).should == {:baz => 'qux',
- :quux => 'corge'}
+ expect(subject.slice(:baz, :fizzle, :quux)).to eq(:baz => 'qux',
+ :quux => 'corge')
end
end
end
@@ -3,14 +3,14 @@
describe Symbol do
it '-- when sent #<=> with a lower symbol -- should return 1' do
- (:foo <=> :bar).should == 1
+ expect(:foo <=> :bar).to eq(1)
end
it '-- when sent #<=> with a higher symbol -- should return -1' do
- (:baz <=> :qux).should == -1
+ expect(:baz <=> :qux).to eq(-1)
end
it '-- when sent #<=> with itself -- should return 0' do
- (:quux <=> :quux).should == 0
+ expect(:quux <=> :quux).to eq(0)
end
end
View
@@ -33,12 +33,12 @@ def do_each_rake_task(&block)
with(task_expression).
and_yield({:name => task_expression})
do_each_rake_task do |t|
- t.should == {:name => task_expression}
+ expect(t).to eq(:name => task_expression)
end
end
it 'should return itself' do
- do_each_rake_task.should == subject
+ expect(do_each_rake_task).to eq(subject)
end
end
@@ -54,9 +54,9 @@ def do_mirror_rake_tasks(*arguments, &block)
describe 'with two scalar arguments --' do
specify do
- lambda {
+ expect {
do_mirror_rake_tasks task_expression, task_expression
- }.should raise_error(ArgumentError, /^wrong number of arguments/)
+ }.to raise_error(ArgumentError, /^wrong number of arguments/)
end
end
@@ -107,7 +107,7 @@ def do_mirror_rake_tasks(*arguments, &block)
end
specify 'by returning itself' do
- do_mirror_rake_tasks.should == subject
+ expect(do_mirror_rake_tasks).to eq(subject)
end
end
@@ -153,7 +153,7 @@ def do_mirror_rake_tasks
end
it 'should return the result of Rake#local_executable' do
- subject.local_rake_executable.should == 'foo'
+ expect(subject.local_rake_executable).to eq('foo')
end
end
@@ -168,7 +168,7 @@ def do_mirror_rake_tasks
end
it 'should return the result of Rake#remote_executable' do
- subject.remote_rake_executable.should == 'foo'
+ expect(subject.remote_rake_executable).to eq('foo')
end
end
end
@@ -34,9 +34,9 @@
it { should == {'foo' => 'bar', 'baz' => 'qux'} }
it 'should index the values as expected' do
- subject['foo'].should == 'bar'
- subject['baz'].should == 'qux'
- subject['not-found'].should be_nil
+ expect(subject['foo']).to eq('bar')
+ expect(subject['baz']).to eq('qux')
+ expect(subject['not-found']).to be_nil
end
describe 'when sent #clear' do
View
@@ -10,15 +10,15 @@
describe '-- when sent #== --' do
it('should recognize equivalent instances to be equal') {
- described_class.new.should == described_class.new
+ expect(described_class.new).to eq(described_class.new)
}
it('should compare using #local_executable') {
- described_class.new.should_not == described_class.new(:local_executable => 'foo')
+ expect(described_class.new).not_to eq(described_class.new(:local_executable => 'foo'))
}
it('should compare using #remote_executable') {
- described_class.new.should_not == described_class.new(:remote_executable => 'foo')
+ expect(described_class.new).not_to eq(described_class.new(:remote_executable => 'foo'))
}
end
@@ -84,11 +84,11 @@
end
it 'should not swallow errors' do
- lambda {
+ expect {
subject.each_task do |t|
raise ZeroDivisionError, 'pow!'
end
- }.should raise_error(ZeroDivisionError, 'pow!')
+ }.to raise_error(ZeroDivisionError, 'pow!')
end
end
@@ -5,13 +5,13 @@
it 'should have a mutable #cd' do
subject.cd '/foo/bar'
- subject.cd.should == '/foo/bar'
+ expect(subject.cd).to eq('/foo/bar')
subject.cd lambda { '/foo/bar' }
- subject.cd.call.should == '/foo/bar'
+ expect(subject.cd.call).to eq('/foo/bar')
subject.cd { '/foo/bar' }
- subject.cd.call.should == '/foo/bar'
+ expect(subject.cd.call).to eq('/foo/bar')
end
it 'should complain about a #cd with the wrong arity' do
@@ -25,14 +25,14 @@
it 'should have a mutable #env' do
subject.env['FOO'] = 'bar'
- subject.env.should == {'FOO' => 'bar'}
+ expect(subject.env).to eq('FOO' => 'bar')
end
its(:options) { should == {} }
it 'should have mutable #options' do
subject.options[:some_option] = 'foo'
- subject.options.should == {:some_option => 'foo'}
+ expect(subject.options).to eq(:some_option => 'foo')
end
its(:rename) { should be_nil }
@@ -41,7 +41,7 @@
subject.rename do |task_name|
"#{task_name}_recipe"
end
- subject.rename.call(:foo).should == 'foo_recipe'
+ expect(subject.rename.call(:foo)).to eq('foo_recipe')
end
it 'should complain about a #rename with the wrong arity' do
View
@@ -4,42 +4,42 @@
describe Cape::Util do
describe '.pluralize' do
it "should pluralize 'foo' as expected" do
- Cape::Util.pluralize('foo').should == 'foos'
+ expect(Cape::Util.pluralize('foo')).to eq('foos')
end
it "should pluralize 'foo' as expected for a count of 2" do
- Cape::Util.pluralize('foo', 2).should == 'foos'
+ expect(Cape::Util.pluralize('foo', 2)).to eq('foos')
end
it "should not pluralize 'foo' for a count of 1" do
- Cape::Util.pluralize('foo', 1).should == 'foo'
+ expect(Cape::Util.pluralize('foo', 1)).to eq('foo')
end
it "should pluralize 'foo' as expected for a count of 0" do
- Cape::Util.pluralize('foo', 0).should == 'foos'
+ expect(Cape::Util.pluralize('foo', 0)).to eq('foos')
end
it "should pluralize 'foo' as expected for a count of -1" do
- Cape::Util.pluralize('foo', -1).should == 'foos'
+ expect(Cape::Util.pluralize('foo', -1)).to eq('foos')
end
end
describe '.to_list_phrase' do
it 'should make the expected list phrase of an empty array' do
- Cape::Util.to_list_phrase([]).should == ''
+ expect(Cape::Util.to_list_phrase([])).to eq('')
end
it 'should make the expected list phrase of a 1-element array' do
- Cape::Util.to_list_phrase(%w(foo)).should == 'foo'
+ expect(Cape::Util.to_list_phrase(%w(foo))).to eq('foo')
end
it 'should make the expected list phrase of a 2-element array' do
- Cape::Util.to_list_phrase(%w(foo bar)).should == 'foo and bar'
+ expect(Cape::Util.to_list_phrase(%w(foo bar))).to eq('foo and bar')
end
it 'should make the expected list phrase of a 3-element array' do
array = %w(foo bar baz)
- Cape::Util.to_list_phrase(array).should == 'foo, bar, and baz'
+ expect(Cape::Util.to_list_phrase(array)).to eq('foo, bar, and baz')
end
end
end
@@ -2,5 +2,5 @@
require 'cape/version'
describe 'Cape::VERSION' do
- specify { Cape::VERSION.should =~ /^\d+\.\d+\.\d+/ }
+ specify { expect(Cape::VERSION).to match(/^\d+\.\d+\.\d+/) }
end
View
@@ -4,69 +4,67 @@
describe Cape::XTerm do
describe '.format' do
it 'should not try to format a nil argument' do
- described_class.format(nil).should be_nil
+ expect(described_class.format(nil)).to be_nil
end
it 'should not try to format a nil argument with a recognized format' do
- described_class.format(nil, :bold).should be_nil
+ expect(described_class.format(nil, :bold)).to be_nil
end
- it 'should complain about an unrecognized format' do
+ specify do
expect {
described_class.format nil, :this_does_not_exist
}.to raise_error(ArgumentError, 'Unrecognized format :this_does_not_exist')
+ end
+
+ specify do
expect {
described_class.format 'foo', :this_does_not_exist
}.to raise_error(ArgumentError, 'Unrecognized format :this_does_not_exist')
end
described_class::FORMATS.each do |format, code|
it "should format a String argument with the #{format.inspect} format" do
- described_class.format('foo', format).should == "\e[#{code}mfoo\e[0m"
+ expect(described_class.format('foo',
+ format)).to eq("\e[#{code}mfoo\e[0m")
end
end
it "should format a String argument with the :bold and :foreground_red formats" do
- described_class.format('foo',
- :bold,
- :foreground_red).should == "\e[1;31mfoo\e[0m"
+ expect(described_class.format('foo',
+ :bold,
+ :foreground_red)).to eq("\e[1;31mfoo\e[0m")
end
end
- it 'should not respond to :this_does_not_exist' do
- described_class.should_not respond_to(:this_does_not_exist)
- end
+ specify { expect(described_class).not_to respond_to(:this_does_not_exist) }
- it '.this_does_not_exist should complain' do
+ specify do
expect {
described_class.this_does_not_exist
}.to raise_error(NoMethodError,
"undefined method `this_does_not_exist' for #{described_class.name}:Module")
end
described_class::FORMATS.each do |format, code|
- it "should respond to .#{format.inspect}" do
- described_class.should respond_to(format)
- end
+ specify { expect(described_class).to respond_to(format) }
describe ".#{format}" do
it "should format a String argument with the #{format.inspect} format" do
- described_class.send(format,
- 'foo').should == described_class.format('foo',
- format)
+ expect(described_class.send(format,
+ 'foo')).to eq(described_class.format('foo',
+ format))
end
end
end
- it 'should respond to .bold_and_foreground_red' do
- described_class.should respond_to(:bold_and_foreground_red)
- end
+ specify { expect(described_class).to respond_to(:bold_and_foreground_red) }
describe '.bold_and_foreground_red' do
it "should format a String argument with the :bold and :foreground_red formats" do
- described_class.bold_and_foreground_red('foo').should == described_class.format('foo',
- :bold,
- :foreground_red)
+ expect(described_class.bold_and_foreground_red('foo')).to eq(described_class.format('foo',
+ :bold,
+ :foreground_red))
end
end
end
View
@@ -14,7 +14,7 @@
Cape do |c|
yielded = c
end
- yielded.should == Cape
+ expect(yielded).to eq(Cape)
end
it 'should accept a nullary block' do
View
@@ -16,4 +16,8 @@
config.order = 'random'
config.alias_it_should_behave_like_to :should_behave_like, 'should behave like'
+
+ config.expect_with :rspec do |c|
+ c.syntax = :expect
+ end
end

0 comments on commit 5f2cf2f

Please sign in to comment.