public
Created

The problem of rspec predicate matchers

  • Download Gist
predicate_matchers.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.