Created
April 7, 2010 15:26
-
-
Save floehopper/359014 to your computer and use it in GitHub Desktop.
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
class MyClass | |
def initialize(array) | |
@array = array | |
end | |
def do_stuff(&block) | |
@array.sort(&block) | |
end | |
end | |
class MyTest < Test::Unit::TestCase | |
def test_should_call_sort_on_array | |
array = [ 1, 2, 3, 4, 5 ] | |
my_object = MyClass.new(array) | |
array.expects(:sort) | |
my_object.do_stuff | |
end | |
def test_should_return_result_of_array_sort | |
array = [ 1, 2, 3, 4, 5 ] | |
my_object = MyClass.new(array) | |
sorted_array = [ 2, 3, 8, 9, 1] | |
array.stubs(:sort).returns(sorted_array) | |
assert_equal sorted_array, my_object.do_stuff | |
end | |
def test_should_call_sort_on_array_with_supplied_block | |
array = [ 1, 2, 3, 4, 5 ] | |
my_object = MyClass.new(array) | |
array.stubs(:sort).yields(1, 2) | |
yielded_values = [] | |
my_object.do_stuff { |a, b| yielded_values << [a, b] } | |
assert_equal [[1, 2]], yielded_values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment