Permalink
Browse files

pull over more features from rspec-core

  • Loading branch information...
1 parent 6f4d7d1 commit 7a9954cca2c732a314caaae104ef4e7d28f19e6e @dchelimsky dchelimsky committed Mar 8, 2010
@@ -7,8 +7,6 @@ Feature: customized message
Scenario: one additional method
Given a file named "node_spec.rb" with:
"""
- require "rspec/expectations"
-
class Node
def initialize(state=:waiting)
@state = state
@@ -0,0 +1,65 @@
+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:
+ """
+ class Counter
+ class << self
+ def increment
+ @count ||= 0
+ @count += 1
+ end
+
+ def count
+ @count ||= 0
+ end
+ end
+ end
+
+ describe Counter, "#increment" do
+ it "should increment the count" do
+ 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)
+ end
+ end
+ """
+ When I run "spec expect_change_spec.rb"
+ Then I should see "2 examples, 1 failure"
+ Then I should see "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:
+ """
+ class Counter
+ class << self
+ def increment
+ @count ||= 0
+ @count += 1
+ end
+
+ def count
+ @count ||= 0
+ end
+ end
+ end
+
+ 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)
+ end
+
+ # deliberate failure
+ it "should not increment the count by 1" do
+ expect{Counter.increment}.to_not change{Counter.count}.by(1)
+ end
+ end
+ """
+ When I run "spec expect_no_change_spec.rb"
+ Then I should see "2 examples, 1 failure"
+ Then I should see "should not have changed, but did change from 1 to 2"
@@ -0,0 +1,44 @@
+Feature: expect error
+
+ Expect a proc to change the state of some object.
+
+ Scenario: expect error
+ Given a file named "expect_error_spec.rb" with:
+ """
+ describe Object, "#non_existent_message" do
+ it "should raise" do
+ expect{Object.non_existent_message}.to raise_error(NameError)
+ end
+ end
+
+ #deliberate failure
+ describe Object, "#public_instance_methods" do
+ it "should raise" do
+ expect{Object.public_instance_methods}.to raise_error(NameError)
+ end
+ end
+ """
+ When I run "spec expect_error_spec.rb"
+ Then I should see "2 examples, 1 failure"
+ Then I should see "expected NameError but nothing was raised"
+
+ Scenario: expect no error
+ Given a file named "expect_no_error_spec.rb" with:
+ """
+ describe Object, "#public_instance_methods" do
+ it "should not raise" do
+ expect{Object.public_instance_methods}.to_not raise_error(NameError)
+ end
+ end
+
+ #deliberate failure
+ describe Object, "#non_existent_message" do
+ it "should not raise" do
+ expect{Object.non_existent_message}.to_not raise_error(NameError)
+ end
+ end
+ """
+ When I run "spec expect_no_error_spec.rb"
+ Then I should see "2 examples, 1 failure"
+ Then I should see "undefined method `non_existent_message'"
+

0 comments on commit 7a9954c

Please sign in to comment.