Created
October 27, 2011 07:41
-
-
Save rgarner/1318993 to your computer and use it in GitHub Desktop.
RSpec example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
class ObjectiveFailure | |
def valid? | |
false | |
end | |
def children | |
['ted'] | |
end | |
def name | |
nil | |
end | |
end | |
describe ObjectiveFailure do | |
it { should be_valid } | |
it { should have(3).children } | |
its(:children) { should include('amelia') } | |
its(:name) { should eql("barry") } | |
end | |
# Output: | |
# | |
# Iggy:spec russ$ rspec my_example_spec.rb | |
# FFFF | |
# | |
# Failures: | |
# | |
# 1) ObjectiveFailure | |
# Failure/Error: it { should be_valid } | |
# expected valid? to return true, got false | |
# # ./my_example_spec.rb:16:in `block (2 levels) in <top (required)>' | |
# | |
# 2) ObjectiveFailure | |
# Failure/Error: it { should have(3).children } | |
# expected 3 children, got 1 | |
# # ./my_example_spec.rb:17:in `block (2 levels) in <top (required)>' | |
# | |
# 3) ObjectiveFailure children | |
# Failure/Error: its(:children) { should include('amelia') } | |
# expected ["ted"] to include "amelia" | |
# Diff: | |
# @@ -1,2 +1,2 @@ | |
# -amelia | |
# +["ted"] | |
# # ./my_example_spec.rb:18:in `block (2 levels) in <top (required)>' | |
# | |
# 4) ObjectiveFailure name | |
# Failure/Error: its(:name) { should eql("barry") } | |
# | |
# expected "barry" | |
# got nil | |
# | |
# (compared using eql?) | |
# # ./my_example_spec.rb:19:in `block (2 levels) in <top (required)>' | |
# | |
# Finished in 0.32004 seconds | |
# 4 examples, 4 failures | |
# | |
# Failed examples: | |
# | |
# rspec ./my_example_spec.rb:16 # ObjectiveFailure | |
# rspec ./my_example_spec.rb:17 # ObjectiveFailure | |
# rspec ./my_example_spec.rb:18 # ObjectiveFailure children | |
# rspec ./my_example_spec.rb:19 # ObjectiveFailure name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment