Skip to content
Browse files

.not_to in addition to .to_not

- Closes #50.
  • Loading branch information...
1 parent 893a7df commit 15573f92400afda37a68ab927fca7d21fbd1b5f4 @dchelimsky dchelimsky committed Feb 5, 2011
Showing with 25 additions and 30 deletions.
  1. +24 −30 features/built_in_matchers/expect_change.feature
  2. +1 −0 lib/rspec/matchers/block_aliases.rb
View
54 features/built_in_matchers/expect_change.feature
@@ -1,9 +1,9 @@
Feature: expect change
- Expect some code (wrapped in a proc) to change the state of some object.
-
- Scenario: expecting change
- Given a file named "expect_change_spec.rb" with:
+ Expect the execution of a block of code to change the state of an object.
+
+ Background:
+ Given a file named "lib/counter.rb" with:
"""
class Counter
class << self
@@ -17,49 +17,43 @@ Feature: expect change
end
end
end
-
+ """
+
+ Scenario: expect change
+ Given a file named "spec/example_spec.rb" with:
+ """
+ require "counter"
+
describe Counter, "#increment" do
it "should increment the count" do
- expect{Counter.increment}.to change{Counter.count}.from(0).to(1)
+ expect { Counter.increment }.to change{Counter.count}.from(0).to(1)
end
# deliberate failure
it "should increment the count by 2" do
- expect{Counter.increment}.to change{Counter.count}.by(2)
+ expect { Counter.increment }.to change{Counter.count}.by(2)
end
end
"""
- When I run "rspec ./expect_change_spec.rb"
- Then the output should contain "2 examples, 1 failure"
+ When I run "rspec spec/example_spec.rb"
+ Then the output should contain "1 failure"
Then the output should contain "should have been changed by 2, but was changed by 1"
- Scenario: expecting no change
- Given a file named "expect_no_change_spec.rb" with:
+ Scenario: expect no change
+ Given a file named "spec/example_spec.rb" with:
"""
- class Counter
- class << self
- def increment
- @count ||= 0
- @count += 1
- end
-
- def count
- @count ||= 0
- end
- end
- end
+ require "counter"
describe Counter, "#increment" do
- it "should not increment the count by 2" do
- expect{Counter.increment}.to_not change{Counter.count}.from(0).to(2)
+ it "should not increment the count by 1 (using to_not)" do
+ expect { Counter.increment }.to_not change{Counter.count}
end
- # deliberate failure
- it "should not increment the count by 1" do
- expect{Counter.increment}.to_not change{Counter.count}.by(1)
+ it "should not increment the count by 1 (using not_to)" do
+ expect { Counter.increment }.not_to change{Counter.count}
end
end
"""
- When I run "rspec ./expect_no_change_spec.rb"
- Then the output should contain "2 examples, 1 failure"
+ When I run "rspec spec/example_spec.rb"
+ Then the output should contain "2 failures"
Then the output should contain "should not have changed, but did change from 1 to 2"
View
1 lib/rspec/matchers/block_aliases.rb
@@ -3,6 +3,7 @@ module Matchers
module BlockAliases
alias_method :to, :should
alias_method :to_not, :should_not
+ alias_method :not_to, :should_not
end
# Extends the submitted block with aliases to and to_not

0 comments on commit 15573f9

Please sign in to comment.
Something went wrong with that request. Please try again.