Skip to content

Instantly share code, notes, and snippets.

@shageman
Created March 8, 2012 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shageman/1998462 to your computer and use it in GitHub Desktop.
Save shageman/1998462 to your computer and use it in GitHub Desktop.
The problem of rspec predicate matchers
require 'rspec/core'
class VeryImportantQuestions
def self.really?(answer)
answer == 'Yes. I am telling you.'
end
def self.really_really?(answer)
answer == 'Yes. I am telling you.' ? 42 : nil
end
end
describe "really?" do
context "using rspec predicate matchers" do
context "if someone is telling you" do
it "should be really really the case and return true" do
VeryImportantQuestions.really?('Yes. I am telling you.').should be_true
end
end
context "if someone is not sure" do
it "should return false" do
VeryImportantQuestions.really?('I am not sure.').should be_false
end
end
end
end
describe "really_really?" do
context "using rspec predicate matchers" do
context "if someone is telling you" do
it "should be really really the case and return true" do
VeryImportantQuestions.really_really?('Yes. I am telling you.').should be_true
end
end
context "if someone is not sure" do
it "should return false" do
VeryImportantQuestions.really_really?('I am not sure.').should be_false
end
end
end
context "spec'ing the actual output of the method fails" do
context "if someone is telling you" do
it "should be really really the case and return true" do
VeryImportantQuestions.really_really?('Yes. I am telling you.').should == true
end
end
context "if someone is not sure" do
it "should return false" do
VeryImportantQuestions.really_really?('I am not sure.').should == false
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment