Skip to content
Browse files

WIP: begin converting to RSpec.

  • Loading branch information...
1 parent 8dfb077 commit 45617186ca33f0c298c68442056e0b16519fec19 @gabebw gabebw committed Apr 10, 2012
View
6 test/acceptance/acceptance_test_helper.rb
@@ -1,11 +1,9 @@
-require File.expand_path('../../test_helper', __FILE__)
+require 'spec_helper'
require 'test_runner'
require 'mocha/configuration'
module AcceptanceTest
-
class FakeLogger
-
attr_reader :warnings
def initialize
@@ -15,7 +13,6 @@ def initialize
def warn(message)
@warnings << message
end
-
end
attr_reader :logger
@@ -34,5 +31,4 @@ def teardown_acceptance_test
Mocha::Configuration.reset_configuration
Mocha::Mockery.instance.logger = @original_logger
end
-
end
View
19 test/acceptance/mocha_example_test.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../test_helper', __FILE__)
+require 'spec_helper'
require 'mocha'
-class MochaExampleTest < Test::Unit::TestCase
-
+describe Mocha::Example do
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
@@ -30,12 +28,14 @@ def right(degrees)
end
def wait
- while (@left_track.moving? or @right_track.moving?); end
+ while (@left_track.moving? || @right_track.moving?)
+ # do nothing
+ end
end
end
- def test_should_step_both_tracks_forward_ten_steps
+ it 'should step both tracks forward ten steps' do
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_metre = 5
@@ -50,7 +50,7 @@ def test_should_step_both_tracks_forward_ten_steps
rover.forward(2)
end
- def test_should_step_both_tracks_backward_ten_steps
+ it 'should step both tracks backward ten steps' do
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_metre = 5
@@ -65,7 +65,7 @@ def test_should_step_both_tracks_backward_ten_steps
rover.backward(2)
end
- def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps
+ it 'should step left track forwards five steps and right track backwards five steps' do
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_degree = 5.0 / 90.0
@@ -80,7 +80,7 @@ def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_fi
rover.right(90)
end
- def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps
+ it 'should step left track backwards five steps and right track forwards five steps' do
left_track = mock('left_track')
right_track = mock('right_track')
steps_per_degree = 5.0 / 90.0
@@ -94,5 +94,4 @@ def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_fi
rover.left(90)
end
-
end
View
54 test/acceptance/spy_test.rb
@@ -1,73 +1,74 @@
-require File.join(File.dirname(__FILE__), "acceptance_test_helper")
+require 'spec_helper'
require 'bourne'
require 'matcher_helpers'
-module SpyTestMethods
-
- def setup
+shared_context_for "Spy Test" do
+ before do
setup_acceptance_test
end
- def teardown
+ after do
teardown_acceptance_test
end
+end
- def test_should_accept_wildcard_stub_call_without_arguments
+shared_examples_for "Spy Test" do
+ it 'should accept wildcard stub call without arguments' do
instance = new_instance
instance.stubs(:magic)
instance.magic
assert_received(instance, :magic)
assert_matcher_accepts have_received(:magic), instance
end
- def test_should_accept_wildcard_stub_call_with_arguments
+ it 'should accept wildcard stub call with arguments' do
instance = new_instance
instance.stubs(:magic)
instance.magic(:argument)
assert_received(instance, :magic)
assert_matcher_accepts have_received(:magic), instance
end
- def test_should_not_accept_wildcard_stub_without_call
+ it 'should not accept wildcard stub without call' do
instance = new_instance
instance.stubs(:magic)
assert_fails { assert_received(instance, :magic) }
assert_fails { assert_matcher_accepts have_received(:magic), instance }
end
- def test_should_not_accept_call_without_arguments
+ it 'should not accept call without arguments' do
instance = new_instance
instance.stubs(:magic)
instance.magic
assert_fails { assert_received(instance, :magic) {|expect| expect.with(1) } }
assert_fails { assert_matcher_accepts have_received(:magic).with(1), instance }
end
- def test_should_not_accept_call_with_different_arguments
+ it 'should not accept call with different arguments' do
instance = new_instance
instance.stubs(:magic)
instance.magic(2)
assert_fails { assert_received(instance, :magic) {|expect| expect.with(1) } }
assert_fails { assert_matcher_accepts have_received(:magic).with(1), instance }
end
- def test_should_accept_call_with_correct_arguments
+ it 'should accept call with correct arguments' do
instance = new_instance
instance.stubs(:magic)
instance.magic(1)
assert_received(instance, :magic) {|expect| expect.with(1) }
assert_matcher_accepts have_received(:magic).with(1), instance
end
- def test_should_accept_call_with_wildcard_arguments
+ it 'should_accept_call_with_wildcard_arguments' do
instance = new_instance
instance.stubs(:magic)
instance.magic('hello')
assert_received(instance, :magic) {|expect| expect.with(is_a(String)) }
assert_matcher_accepts have_received(:magic).with(is_a(String)), instance
end
- def test_should_reject_call_on_different_mock
+ it 'should reject call on different mock' do
instance = new_instance
other = new_instance
instance.stubs(:magic)
@@ -77,15 +78,15 @@ def test_should_reject_call_on_different_mock
assert_fails { assert_matcher_accepts have_received(:magic).with(is_a(String)), instance }
end
- def test_should_accept_correct_number_of_calls
+ it 'should accept correct number of calls' do
instance = new_instance
instance.stubs(:magic)
2.times { instance.magic }
assert_received(instance, :magic) {|expect| expect.twice }
assert_matcher_accepts have_received(:magic).twice, instance
end
- def test_should_not_allow_should_not
+ it 'should not allow should not' do
begin
have_received(:magic).does_not_match?(new_instance)
rescue Mocha::API::InvalidHaveReceived => exception
@@ -95,13 +96,13 @@ def test_should_not_allow_should_not
flunk("Expected to fail")
end
- def test_should_warn_for_unstubbed_methods_with_expectations
+ it 'should warn for unstubbed methods with expectations' do
new_instance.stubs(:unknown)
assert_fails(/unstubbed, expected exactly once/) { assert_matcher_accepts have_received(:unknown), new_instance }
end
- def test_should_reject_not_enough_calls
+ it 'should reject not enough calls' do
instance = new_instance
instance.stubs(:magic)
instance.magic
@@ -110,7 +111,7 @@ def test_should_reject_not_enough_calls
assert_fails(message) { assert_matcher_accepts have_received(:magic).twice, instance }
end
- def test_should_reject_too_many_calls
+ it 'should reject too many calls' do
instance = new_instance
instance.stubs(:magic)
2.times { instance.magic }
@@ -128,12 +129,12 @@ def assert_fails(message=/not yet invoked/)
end
flunk("Expected to fail")
end
-
end
class PartialSpyTest < Test::Unit::TestCase
include AcceptanceTest
- include SpyTestMethods
+ include_context "Spy Test"
+ it_behaves_like "Spy Test"
def new_instance
Object.new
@@ -142,23 +143,26 @@ def new_instance
class PureSpyTest < Test::Unit::TestCase
include AcceptanceTest
- include SpyTestMethods
+ include_context "Spy Test"
+ it_behaves_like "Spy Test"
def new_instance
stub
end
end
-class StubEverythingSpyTest < Test::Unit::TestCase
+describe 'stub_everything spy' do
include AcceptanceTest
- def setup
+
+ before do
setup_acceptance_test
end
- def teardown
+ after do
teardown_acceptance_test
end
- def test_should_match_invocations_with_no_explicit_stubbing
+
+ it 'should match invocations with no explicit stubbing' do
instance = stub_everything
instance.surprise!
assert_received(instance, :surprise!)
View
30 test/acceptance/stubba_example_test.rb
@@ -1,71 +1,64 @@
-require File.expand_path('../../test_helper', __FILE__)
+require 'spec_helper'
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
+describe 'Stubba Example' do
+ it 'should stub instance method' do
widget = Widget.new
widget.expects(:model).returns('different_model')
assert_equal 'different_model', widget.model
end
- def test_should_stub_module_method
+ it 'should stub module method' do
should_stub_module_method
end
- def test_should_stub_module_method_again
+ it 'should stub module method again' do
should_stub_module_method
end
- def test_should_stub_class_method
+ it 'should stub class method' do
should_stub_class_method
end
- def test_should_stub_class_method_again
+ it 'should stub class method again' do
should_stub_class_method
end
- def test_should_stub_instance_method_on_any_instance_of_a_class
+ it 'should stub instance method on any instance of a class' do
should_stub_instance_method_on_any_instance_of_a_class
end
- def test_should_stub_instance_method_on_any_instance_of_a_class_again
+ it 'should stub instance method on any instance of a class again' do
should_stub_instance_method_on_any_instance_of_a_class
end
- def test_should_stub_two_different_class_methods
+ it 'should stub two different class methods' do
should_stub_two_different_class_methods
end
- def test_should_stub_two_different_class_methods_again
+ it 'should stub two different class methods again' do
should_stub_two_different_class_methods
end
@@ -98,5 +91,4 @@ def should_stub_instance_method_on_any_instance_of_a_class
assert_equal 'another_model', widget_1.model
assert_equal 'another_model', widget_2.model
end
-
end
View
1 test/unit/assert_received_test.rb
@@ -5,7 +5,6 @@
require 'mocha/object'
class AssertReceivedTest < Test::Unit::TestCase
-
include Mocha
include TestRunner
include Mocha::API

0 comments on commit 4561718

Please sign in to comment.
Something went wrong with that request. Please try again.