Skip to content

Instantly share code, notes, and snippets.

@latentflip
Created June 10, 2013 12:16
Show Gist options
  • Save latentflip/5748310 to your computer and use it in GitHub Desktop.
Save latentflip/5748310 to your computer and use it in GitHub Desktop.
Testing Puts
class MyClass
def initialize(word)
@word = word
end
def putter
puts @word
end
end
describe "MyClass" do
it "should put 'foo'" do
myobj = MyClass.new('foo')
myobj.should_receive(:puts).with('foo')
myobj.putter
end
end
@latentflip
Copy link
Author

Notably, puts is not mixed into ruby 1.9's BasicObject, so if you try to do this:

class MyClass < BasicObject
  def putter
    puts 'foo'
  end
end

MyClass.new.putter

You'll get:

NoMethodError: undefined method `puts' for #<MyClass:0x00000100cdfae0>
        from (irb):3:in `putter'
        from (irb):6
        from /Users/Roberts/.rvm/rubies/ruby-1.9.3-p125-perf/bin/irb:16:in `<main>'

Which is kinda confusing, till you remember puts is just a method on your object, and BasicObject is a very bare object so has no puts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment