Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created November 16, 2010 14:15
Show Gist options
  • Save j1n3l0/701864 to your computer and use it in GitHub Desktop.
Save j1n3l0/701864 to your computer and use it in GitHub Desktop.
HowTo: test private methods in Ruby [ruby, test]
# HowTo: test private methods in Ruby
#
# @author Nelo Onyiah
require "rubygems"
require "shoulda"
module Baz
private
def quux
"Hello, World!"
end
end
class Foo
private
def bar
42
end
end
class TestFoo < Test::Unit::TestCase
include Baz
public :quux
context "A new Foo" do
setup do
@foo = Foo.new
end
should "have bar == 42" do
assert_equal 42, @foo.send( :bar )
end
should "have quux == 'Hello, World!'" do
assert_equal "Hello, World!", quux
end
end
end
@j1n3l0
Copy link
Author

j1n3l0 commented Nov 16, 2010

See this thread on stackoverflow for details

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