Created
November 30, 2012 19:34
-
-
Save jwo/4177999 to your computer and use it in GitHub Desktop.
message vs value expection (for @RubyoffRails)
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
describe Fixnum do | |
it "should add 2 + 2 and return 4" do | |
@two = 2 | |
result = @two+ @two | |
result.should eq(4) | |
end | |
end | |
class Calculator | |
def self.slugify_the_words(words) | |
words.join("-").downcase | |
end | |
def self.sum(values) | |
values.inject(:+) | |
end | |
end | |
class Person | |
attr_reader :first_name, :last_name, :nerd | |
def initialize(first_name, last_name, nerd) | |
@first_name = first_name | |
@last_name = last_name | |
@nerd = nerd | |
end | |
def calculate_sum(numbers) | |
Calculator.sum(numbers) | |
end | |
def nerd? | |
@nerd == true | |
end | |
end | |
describe Calculator do | |
it "should slug the words" do | |
result = Calculator.slugify_the_words(["The", "Words", "Are", "cool"]) | |
result.should eq("the-words-are-cool") | |
end | |
it "should add up all the numbers" do | |
# value expectation | |
Calculator.sum([5,10,25]).should eq(40) | |
end | |
end | |
describe Person do | |
it "should be a nerd if we tell it to" do | |
person = Person.new("jeff", "corvette", true) | |
# all value expectations | |
person.nerd.should eq(true) | |
person.nerd.should be_true | |
person.should be_a_nerd | |
end | |
describe ":calculate_sum" do | |
it "should use the calculator" do | |
# message expectation! | |
Calculator.should_receive(:sum).with([5,10,25]) | |
person = Person.new("jeff", "corvette", true) | |
person.calculate_sum([5,10,25]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment