Skip to content

Commit

Permalink
Update RSpec
Browse files Browse the repository at this point in the history
* Use RSpec 3.1.x
* Use expect syntax
* Avoid operator matchers
  • Loading branch information
jferris authored and mike-burns committed Oct 30, 2014
1 parent 9e91379 commit c9f99df
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
72 changes: 36 additions & 36 deletions spec/wrapped_spec.rb
Expand Up @@ -8,16 +8,16 @@
let(:delegator) { SimpleDelegator.new(value).wrapped }

it "converts the value to a Present" do
just.should be_instance_of(Present)
expect(just).to be_instance_of(Present)
end

it "converts the nil to a Blank" do
nothing.should be_instance_of(Blank)
expect(nothing).to be_instance_of(Blank)
end

it "converts a simple delegator to a Present" do
delegator.should be_instance_of(Present)
delegator.unwrap.should be_instance_of(SimpleDelegator)
expect(delegator).to be_instance_of(Present)
expect(delegator.unwrap).to be_instance_of(SimpleDelegator)
end
end

Expand All @@ -27,7 +27,7 @@
let(:nothing) { nil.wrapped }

it 'produces the value of the wrapped object' do
just.unwrap.should == value
expect(just.unwrap).to eq(value)
end

it 'raises an exception when called on the wrapped nil' do
Expand All @@ -43,38 +43,38 @@
it 'calls the proper callback for a wrapped value' do
result = false
just.present {|v| result = v}
result.should be_true
expect(result).to be_truthy
end

it 'calls the proper callback for a wrapped nil' do
result = false
nothing.blank {result = true}
result.should be_true
expect(result).to be_truthy
end

it 'ignores the other callback for a wrapped value' do
result = true
just.blank { result = false }
result.should be_true
expect(result).to be_truthy
end


it 'ignores the other callback for a wrapped nil' do
result = true
nothing.present { result = false }
result.should be_true
expect(result).to be_truthy
end

it 'chains for wrapped values' do
result = false
just.present { result = true }.blank { result = false }
result.should be_true
expect(result).to be_truthy
end

it 'chains for wrapped nils' do
result = false
nothing.present { result = false }.blank { result = true }
result.should be_true
expect(result).to be_truthy
end
end

Expand All @@ -89,29 +89,29 @@
it 'acts over the value for #each on a wrapped value' do
result = -1
just.each {|v| result = v }
result.should == value
expect(result).to eq(value)
end

it 'produces a singleton array of the value for a wrapped value on #each' do
just.each.should == [value]
expect(just.each).to eq([value])
end

it 'skips the block for #each on a wrapped nil' do
result = -1
nothing.each {|v| result = v }
result.should == -1
expect(result).to eq(-1)
end

it 'produces the empty array for a wrapped nil on #each' do
nothing.each.should be_empty
expect(nothing.each).to be_empty
end

it 'maps over the value for a wrapped value' do
just.map {|n| n + 1}.should == [value+1]
expect(just.map {|n| n + 1}).to eq([value+1])
end

it 'map produces the empty list for a wrapped nil' do
nothing.map {|n| n + 1}.should == []
expect(nothing.map {|n| n + 1}).to eq([])
end
end

Expand All @@ -121,13 +121,13 @@
let(:nothing) { nil.wrapped }

it 'knows whether it is present' do
just.should be_present
nothing.should_not be_present
expect(just).to be_present
expect(nothing).not_to be_present
end

it 'knows whether it is blank' do
just.should_not be_blank
nothing.should be_blank
expect(just).not_to be_blank
expect(nothing).to be_blank
end
end

Expand All @@ -137,19 +137,19 @@
let(:nothing) { nil.wrapped }

it 'produces the value for a wrapped value' do
just.unwrap_or(-1).should == value
expect(just.unwrap_or(-1)).to eq(value)
end

it 'produces the default for a wrapped nil' do
nothing.unwrap_or(-1).should == -1
expect(nothing.unwrap_or(-1)).to eq(-1)
end

it 'produces the value of the block for a wrapped object' do
just.unwrap_or(-1) {|n| n+1}.should == value + 1
expect(just.unwrap_or(-1) {|n| n+1}).to eq(value + 1)
end

it 'produces the default for a wrapped nil even with a block' do
nothing.unwrap_or(-1) {2}.should == -1
expect(nothing.unwrap_or(-1) {2}).to eq(-1)
end
end

Expand All @@ -159,11 +159,11 @@
let(:nothing) { nil.wrapped }

it 'produces the value from #flat_map for a wrapped value' do
just.flat_map {|n| (n+1).wrapped }.unwrap.should == value+1
expect(just.flat_map {|n| (n+1).wrapped }.unwrap).to eq(value+1)
end

it 'produces blank from #flat_map for a wrapped nil' do
nothing.flat_map {|n| (n+1).wrapped}.should be_blank
expect(nothing.flat_map {|n| (n+1).wrapped}).to be_blank
end
end

Expand All @@ -173,40 +173,40 @@
let(:nothing) { nil.wrapped }

it 'unwraps, applies the block, then re-wraps for a wrapped value' do
just.fmap {|n| n+1}.unwrap.should == value+1
expect(just.fmap {|n| n+1}.unwrap).to eq(value+1)
end

it 'produces the blank for a wrapped nil' do
nothing.fmap {|n| n+1}.should be_blank
expect(nothing.fmap {|n| n+1}).to be_blank
end
end

describe Wrapped, 'equality' do
it 'is equal with the same wrapped value' do
1.wrapped.should == 1.wrapped
expect(1.wrapped).to eq(1.wrapped)
end

it 'is not equal with a different wrapped value' do
1.wrapped.should_not == 2.wrapped
expect(1.wrapped).not_to eq(2.wrapped)
end

it 'is equal with two wrapped nils' do
nil.wrapped.should == nil.wrapped
expect(nil.wrapped).to eq(nil.wrapped)
end

it 'is not equal with a wrapped nil and a wrapped value' do
nil.wrapped.should_not == 1.wrapped
expect(nil.wrapped).not_to eq(1.wrapped)
end

it 'is not equal with a wrapped value and a wrapped nil' do
1.wrapped.should_not == nil.wrapped
expect(1.wrapped).not_to eq(nil.wrapped)
end

it 'is not equal with a present value and un unwrapped value' do
1.wrapped.should_not == 1
expect(1.wrapped).not_to eq(1)
end

it 'is not equal with a blank value and an unwrapped value' do
nil.wrapped.should_not == 1
expect(nil.wrapped).not_to eq(1)
end
end
4 changes: 2 additions & 2 deletions wrapped.gemspec
Expand Up @@ -16,6 +16,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_paths = ["lib"]

s.add_development_dependency('rspec', '~> 2.3')
s.add_development_dependency('rake')
s.add_development_dependency("rspec", "~> 3.1.0")
s.add_development_dependency("rake")
end

0 comments on commit c9f99df

Please sign in to comment.