Permalink
Browse files

Remove trailing whitespace.

  • Loading branch information...
1 parent 650afb0 commit c3cc6bdde25a17e8d66726cbcb03db98a02bbb94 @tristandunn tristandunn committed Mar 9, 2012
@@ -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
@@ -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
@@ -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)
@@ -148,10 +148,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!
@@ -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
@@ -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
@@ -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
View
@@ -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])
@@ -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
View
@@ -1,7 +1,7 @@
require 'metaclass'
module Mocha
-
+
module ObjectMethods
def define_instance_method(method_symbol, &block)
__metaclass__.send(:define_method, method_symbol, block)
@@ -16,7 +16,7 @@ def define_instance_accessor(*symbols)
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
end
end
-
+
end
class Object
Oops, something went wrong.

0 comments on commit c3cc6bd

Please sign in to comment.