Permalink
Browse files

simplify feature

  • Loading branch information...
1 parent 8729e9a commit 2b7b0d8fbc46247983130f2b87f20c5ca270ee9f @dchelimsky dchelimsky committed Nov 15, 2010
Showing with 14 additions and 46 deletions.
  1. +14 −46 features/expectations/customized_message.feature
@@ -1,54 +1,22 @@
Feature: customized message
- In order to get the feedback I want
- As an RSpec user
- I want to customize the failure message per example
+ RSpec tries to provide useful failure messages, but for cases in which you
+ want more specific information, you can define your own message right in the
+ example. This works for any matcher _other than the operator matchers_.
- Scenario: one additional method
- Given a file named "node_spec.rb" with:
+ Scenario: customize failure message
+ Given a file named "example_spec.rb" with:
"""
- class Node
- def initialize(state=:waiting)
- @state = state
- end
- def state
- @state
- end
- def waiting?
- @state == :waiting
- end
- def started?
- @state == :started
- end
- def start
- @state = :started
- end
- end
-
- describe "a new Node" do
- it "should be waiting" do
- node = Node.new(:started) #start w/ started to trigger failure
- node.should be_waiting, "node.state: #{node.state} (first example)"
- end
-
- it "should not be started" do
- node = Node.new(:started) #start w/ started to trigger failure
- node.should_not be_started, "node.state: #{node.state} (second example)"
- end
- end
-
- describe "node.start" do
- it "should change the state" do
- node = Node.new(:started) #start w/ started to trigger failure
- lambda {node.start}.should change{node.state}, "expected a change"
+ describe Array do
+ context "when created with `new`" do
+ it "is empty" do
+ array = Array.new
+ array << 1 # trigger a failure to demonstrate the message
+ array.should be_empty, "expected empty array, got #{array.inspect}"
+ end
end
end
"""
- When I run "rspec ./node_spec.rb --format documentation"
- Then the output should contain "3 examples, 3 failures"
- And the output should not contain "to return true, got false"
- And the output should not contain "to return false, got true"
- And the output should contain "node.state: started (first example)"
- And the output should contain "node.state: started (second example)"
- And the output should contain "expected a change"
+ When I run "rspec example_spec.rb --format documentation"
+ Then the output should contain "expected empty array, got [1]"

0 comments on commit 2b7b0d8

Please sign in to comment.