Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created September 7, 2011 23:32
Show Gist options
  • Save tenderlove/1202145 to your computer and use it in GitHub Desktop.
Save tenderlove/1202145 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
class Subject < Struct.new(:lol)
def render_controls
lol.button_to 'Vote'
end
end
describe 'lolwot' do
it "should generate a button" do
template = Object.new
tc = self
called = false
template.extend Module.new {
define_method(:button_to) do |arg|
called = true
tc.assert_equal "Vote", arg
"THE_HTML"
end
}
subject = Subject.new template
subject.render_controls.must_equal "THE_HTML"
assert called, 'button_to was called'
end
it "should do it with minitest/mock" do
template = MiniTest::Mock.new
template.expect :button_to, "THE_HTML", ["Vote"]
subject = Subject.new template
subject.render_controls.must_equal "THE_HTML"
template.verify
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment