features/built_in_matchers/equality.feature in rspec-expectations-2.99.2 vs features/built_in_matchers/equality.feature in rspec-expectations-3.0.0.beta1
- old
+ new
@@ -11,41 +11,38 @@
semantics.
rspec-expectations ships with matchers that align with each of these methods:
```ruby
- a.should equal(b) # passes if a.equal?(b)
- a.should eql(b) # passes if a.eql?(b)
- a.should == b # passes if a == b
+ expect(a).to equal(b) # passes if a.equal?(b)
+ expect(a).to eql(b) # passes if a.eql?(b)
+ expect(a).to be == b # passes if a == b
```
It also ships with two matchers that have more of a DSL feel to them:
```ruby
- a.should be(b) # passes if a.equal?(b)
- a.should eq(b) # passes if a == b
+ expect(a).to be(b) # passes if a.equal?(b)
+ expect(a).to eq(b) # passes if a == b
```
- These are a useful pair if you wish to avoid the warning that Ruby emits on
- `a.should == b`
-
Scenario: compare using eq (==)
Given a file named "compare_using_eq.rb" with:
"""ruby
describe "a string" do
it "is equal to another string of the same value" do
- "this string".should eq("this string")
+ expect("this string").to eq("this string")
end
it "is not equal to another string of a different value" do
- "this string".should_not eq("a different string")
+ expect("this string").not_to eq("a different string")
end
end
describe "an integer" do
it "is equal to a float of the same value" do
- 5.should eq(5.0)
+ expect(5).to eq(5.0)
end
end
"""
When I run `rspec compare_using_eq.rb`
Then the output should contain "3 examples, 0 failures"
@@ -53,21 +50,21 @@
Scenario: compare using ==
Given a file named "compare_using_==.rb" with:
"""ruby
describe "a string" do
it "is equal to another string of the same value" do
- "this string".should == "this string"
+ expect("this string").to be == "this string"
end
it "is not equal to another string of a different value" do
- "this string".should_not == "a different string"
+ expect("this string").not_to be == "a different string"
end
end
describe "an integer" do
it "is equal to a float of the same value" do
- 5.should == 5.0
+ expect(5).to be == 5.0
end
end
"""
When I run `rspec compare_using_==.rb`
Then the output should contain "3 examples, 0 failures"
@@ -75,19 +72,19 @@
Scenario: compare using eql (eql?)
Given a file named "compare_using_eql.rb" with:
"""ruby
describe "an integer" do
it "is equal to another integer of the same value" do
- 5.should eql(5)
+ expect(5).to eql(5)
end
it "is not equal to another integer of a different value" do
- 5.should_not eql(6)
+ expect(5).not_to eql(6)
end
it "is not equal to a float of the same value" do
- 5.should_not eql(5.0)
+ expect(5).not_to eql(5.0)
end
end
"""
When I run `rspec compare_using_eql.rb`
@@ -97,19 +94,19 @@
Given a file named "compare_using_equal.rb" with:
"""ruby
describe "a string" do
it "is equal to itself" do
string = "this string"
- string.should equal(string)
+ expect(string).to equal(string)
end
it "is not equal to another string of the same value" do
- "this string".should_not equal("this string")
+ expect("this string").not_to equal("this string")
end
it "is not equal to another string of a different value" do
- "this string".should_not equal("a different string")
+ expect("this string").not_to equal("a different string")
end
end
"""
When I run `rspec compare_using_equal.rb`
@@ -119,18 +116,18 @@
Given a file named "compare_using_be.rb" with:
"""ruby
describe "a string" do
it "is equal to itself" do
string = "this string"
- string.should be(string)
+ expect(string).to be(string)
end
it "is not equal to another string of the same value" do
- "this string".should_not be("this string")
+ expect("this string").not_to be("this string")
end
it "is not equal to another string of a different value" do
- "this string".should_not be("a different string")
+ expect("this string").not_to be("a different string")
end
end
"""
When I run `rspec compare_using_be.rb`