Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10 from tristandunn/trailing-whitespace
Remove trailing whitespace.
  • Loading branch information
Gabe Berke-Williams committed Mar 9, 2012
2 parents 4bbe610 + c3cc6bd commit 5a39f66
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 225 deletions.
18 changes: 9 additions & 9 deletions test/acceptance/acceptance_test_helper.rb
Expand Up @@ -3,36 +3,36 @@
require 'mocha/configuration'

module AcceptanceTest

class FakeLogger

attr_reader :warnings

def initialize
@warnings = []
end

def warn(message)
@warnings << message
end

end

attr_reader :logger

include TestRunner

def setup_acceptance_test
Mocha::Configuration.reset_configuration
@logger = FakeLogger.new
mockery = Mocha::Mockery.instance
@original_logger = mockery.logger
mockery.logger = @logger
end

def teardown_acceptance_test
Mocha::Configuration.reset_configuration
Mocha::Mockery.instance.logger = @original_logger
end

end
52 changes: 26 additions & 26 deletions test/acceptance/mocha_example_test.rb
Expand Up @@ -2,97 +2,97 @@
require 'mocha'

class MochaExampleTest < Test::Unit::TestCase

class Rover

def initialize(left_track, right_track, steps_per_metre, steps_per_degree)
@left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree
end

def forward(metres)
@left_track.step(metres * @steps_per_metre)
@right_track.step(metres * @steps_per_metre)
wait
end

def backward(metres)
forward(-metres)
end

def left(degrees)
@left_track.step(-degrees * @steps_per_degree)
@right_track.step(+degrees * @steps_per_degree)
wait
end

def right(degrees)
left(-degrees)
end

def wait
while (@left_track.moving? or @right_track.moving?); end
end

end

def test_should_step_both_tracks_forward_ten_steps
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_metre = 5
rover = Rover.new(left_track, right_track, steps_per_metre, nil)

left_track.expects(:step).with(10)
right_track.expects(:step).with(10)

left_track.stubs(:moving?).returns(false)
right_track.stubs(:moving?).returns(false)

rover.forward(2)
end

def test_should_step_both_tracks_backward_ten_steps
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_metre = 5
rover = Rover.new(left_track, right_track, steps_per_metre, nil)

left_track.expects(:step).with(-10)
right_track.expects(:step).with(-10)

left_track.stubs(:moving?).returns(false)
right_track.stubs(:moving?).returns(false)

rover.backward(2)
end

def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_degree = 5.0 / 90.0
rover = Rover.new(left_track, right_track, nil, steps_per_degree)

left_track.expects(:step).with(+5)
right_track.expects(:step).with(-5)

left_track.stubs(:moving?).returns(false)
right_track.stubs(:moving?).returns(false)

rover.right(90)
end

def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_degree = 5.0 / 90.0
rover = Rover.new(left_track, right_track, nil, steps_per_degree)

left_track.expects(:step).with(-5)
right_track.expects(:step).with(+5)

left_track.stubs(:moving?).returns(false)
right_track.stubs(:moving?).returns(false)

rover.left(90)
end
end

end
8 changes: 4 additions & 4 deletions test/acceptance/spy_test.rb
Expand Up @@ -7,11 +7,11 @@ module SpyTestMethods
def setup
setup_acceptance_test
end

def teardown
teardown_acceptance_test
end

def test_should_accept_wildcard_stub_call_without_arguments
instance = new_instance
instance.stubs(:magic)
Expand Down Expand Up @@ -154,10 +154,10 @@ class StubEverythingSpyTest < Test::Unit::TestCase
def setup
setup_acceptance_test
end

def teardown
teardown_acceptance_test
end
end
def test_should_match_invocations_with_no_explicit_stubbing
instance = stub_everything
instance.surprise!
Expand Down
48 changes: 24 additions & 24 deletions test/acceptance/stubba_example_test.rb
Expand Up @@ -2,86 +2,86 @@
require 'mocha'

class Widget

def model
'original_model'
end

class << self

def find(options)
[]
end

def create(attributes)
Widget.new
end

end

end

module Thingy

def self.wotsit
:hoojamaflip
end

end

class StubbaExampleTest < Test::Unit::TestCase

def test_should_stub_instance_method
widget = Widget.new
widget.expects(:model).returns('different_model')
assert_equal 'different_model', widget.model
end

def test_should_stub_module_method
should_stub_module_method
end

def test_should_stub_module_method_again
should_stub_module_method
end

def test_should_stub_class_method
should_stub_class_method
end

def test_should_stub_class_method_again
should_stub_class_method
end

def test_should_stub_instance_method_on_any_instance_of_a_class
should_stub_instance_method_on_any_instance_of_a_class
end

def test_should_stub_instance_method_on_any_instance_of_a_class_again
should_stub_instance_method_on_any_instance_of_a_class
end

def test_should_stub_two_different_class_methods
should_stub_two_different_class_methods
end

def test_should_stub_two_different_class_methods_again
should_stub_two_different_class_methods
end

private

def should_stub_module_method
Thingy.expects(:wotsit).returns(:dooda)
assert_equal :dooda, Thingy.wotsit
end

def should_stub_class_method
widgets = [Widget.new]
Widget.expects(:find).with(:all).returns(widgets)
assert_equal widgets, Widget.find(:all)
end
end

def should_stub_two_different_class_methods
found_widgets = [Widget.new]
created_widget = Widget.new
Expand All @@ -90,7 +90,7 @@ def should_stub_two_different_class_methods
assert_equal found_widgets, Widget.find(:all)
assert_equal created_widget, Widget.create(:model => 'wombat')
end

def should_stub_instance_method_on_any_instance_of_a_class
Widget.any_instance.expects(:model).at_least_once.returns('another_model')
widget_1 = Widget.new
Expand All @@ -99,4 +99,4 @@ def should_stub_instance_method_on_any_instance_of_a_class
assert_equal 'another_model', widget_2.model
end

end
end
14 changes: 7 additions & 7 deletions test/execution_point.rb
@@ -1,20 +1,20 @@
class ExecutionPoint

attr_reader :backtrace

def self.current
new(caller)
end

def initialize(backtrace)
@backtrace = backtrace
end

def file_name
return "unknown" unless @backtrace && @backtrace.first
/\A(.*?):\d+/.match(@backtrace.first)[1]
end

def line_number
return "unknown" unless @backtrace && @backtrace.first
Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
Expand All @@ -24,13 +24,13 @@ def ==(other)
return false unless other.is_a?(ExecutionPoint)
(file_name == other.file_name) and (line_number == other.line_number)
end

def to_s
"file: #{file_name}; line: #{line_number}"
end

def inspect
to_s
end

end
4 changes: 2 additions & 2 deletions test/method_definer.rb
@@ -1,7 +1,7 @@
require 'metaclass'

module Mocha

module ObjectMethods
def define_instance_method(method_symbol, &block)
__metaclass__.send(:define_method, method_symbol, block)
Expand All @@ -16,7 +16,7 @@ def define_instance_accessor(*symbols)
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
end
end

end

class Object
Expand Down

0 comments on commit 5a39f66

Please sign in to comment.