rr 0.3.11 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +8 -3
- data/README +130 -39
- data/Rakefile +6 -5
- data/lib/rr.rb +8 -8
- data/lib/rr/adapters/rr_methods.rb +228 -0
- data/lib/rr/adapters/rspec.rb +1 -1
- data/lib/rr/adapters/test_unit.rb +1 -1
- data/lib/rr/double.rb +294 -89
- data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
- data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
- data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
- data/lib/rr/double_insertion.rb +132 -0
- data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
- data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
- data/lib/rr/errors/argument_equality_error.rb +3 -3
- data/lib/rr/errors/rr_error.rb +13 -13
- data/lib/rr/errors/scenario_definition_error.rb +3 -3
- data/lib/rr/errors/scenario_not_found_error.rb +3 -3
- data/lib/rr/errors/scenario_order_error.rb +3 -3
- data/lib/rr/errors/times_called_error.rb +3 -3
- data/lib/rr/expectations/any_argument_expectation.rb +1 -1
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/hash_with_object_id_key.rb +1 -1
- data/lib/rr/space.rb +40 -40
- data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
- data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
- data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
- data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
- data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
- data/lib/rr/times_called_matchers/terminal.rb +16 -16
- data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
- data/spec/core_spec_suite.rb +18 -0
- data/{examples → spec}/environment_fixture_setup.rb +0 -1
- data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
- data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
- data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
- data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
- data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
- data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
- data/spec/rr/double/double_insertion_spec.rb +66 -0
- data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
- data/spec/rr/double_creator_spec.rb +454 -0
- data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
- data/spec/rr/double_method_proxy_spec.rb +71 -0
- data/spec/rr/double_spec.rb +654 -0
- data/spec/rr/errors/rr_error_spec.rb +65 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_create_spec.rb +278 -0
- data/spec/rr/space/space_helper.rb +7 -0
- data/spec/rr/space/space_register_spec.rb +32 -0
- data/spec/rr/space/space_reset_spec.rb +131 -0
- data/spec/rr/space/space_spec.rb +32 -0
- data/spec/rr/space/space_verify_spec.rb +181 -0
- data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
- data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
- data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rspec_spec_suite.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
- data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
- metadata +93 -93
- data/examples/core_example_suite.rb +0 -31
- data/examples/example_helper.rb +0 -9
- data/examples/rr/double/double_bind_example.rb +0 -70
- data/examples/rr/double/double_dispatching_example.rb +0 -236
- data/examples/rr/double/double_example.rb +0 -66
- data/examples/rr/double/double_has_original_method_example.rb +0 -56
- data/examples/rr/double/double_register_scenario_example.rb +0 -24
- data/examples/rr/double/double_reset_example.rb +0 -89
- data/examples/rr/double/double_verify_example.rb +0 -23
- data/examples/rr/errors/rr_error_example.rb +0 -65
- data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
- data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
- data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
- data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
- data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
- data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
- data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
- data/examples/rr/rspec/rspec_usage_example.rb +0 -65
- data/examples/rr/scenario_creator_example.rb +0 -459
- data/examples/rr/scenario_example.rb +0 -701
- data/examples/rr/scenario_method_proxy_example.rb +0 -71
- data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
- data/examples/rr/space/space_create_example.rb +0 -278
- data/examples/rr/space/space_example.rb +0 -29
- data/examples/rr/space/space_helper.rb +0 -7
- data/examples/rr/space/space_register_example.rb +0 -32
- data/examples/rr/space/space_reset_example.rb +0 -120
- data/examples/rr/space/space_verify_example.rb +0 -169
- data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
- data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
- data/examples/rspec_example_suite.rb +0 -25
- data/lib/rr/extensions/instance_methods.rb +0 -228
- data/lib/rr/scenario.rb +0 -337
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation, " with RangeMatcher" do
|
6
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
7
|
+
attr_reader :matcher
|
8
|
+
|
9
|
+
before do
|
10
|
+
@matcher = TimesCalledMatchers::RangeMatcher.new(1..2)
|
11
|
+
@expectation = TimesCalledExpectation.new(scenario, matcher)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#verify" do
|
15
|
+
it "returns true when times called falls within a range" do
|
16
|
+
expectation.verify.should == false
|
17
|
+
expectation.attempt!
|
18
|
+
expectation.verify.should == true
|
19
|
+
expectation.attempt!
|
20
|
+
expectation.verify.should == true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#verify! when passed a Range (1..2)" do
|
25
|
+
it "passes after attempt! called 1 time" do
|
26
|
+
expectation.attempt!
|
27
|
+
expectation.verify!
|
28
|
+
end
|
29
|
+
|
30
|
+
it "passes after attempt! called 2 times" do
|
31
|
+
expectation.attempt!
|
32
|
+
expectation.attempt!
|
33
|
+
expectation.verify!
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can't be called when attempt! is called 3 times" do
|
37
|
+
expectation.attempt!
|
38
|
+
expectation.attempt!
|
39
|
+
proc do
|
40
|
+
expectation.attempt!
|
41
|
+
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#attempt? with RangeMatcher" do
|
46
|
+
it "returns true when attempted less than low end of range" do
|
47
|
+
expectation.should be_attempt
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns false when attempted in range" do
|
51
|
+
expectation.attempt!
|
52
|
+
expectation.should be_attempt
|
53
|
+
expectation.attempt!
|
54
|
+
expectation.should be_attempt
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises error before attempted more than expected times" do
|
58
|
+
2.times {expectation.attempt!}
|
59
|
+
proc {expectation.attempt!}.should raise_error(
|
60
|
+
Errors::TimesCalledError
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#attempt! for a range expectation" do
|
66
|
+
it "raises error when attempt! called more than range permits" do
|
67
|
+
expectation.attempt!
|
68
|
+
expectation.attempt!
|
69
|
+
raises_expectation_error {expectation.attempt!}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#terminal? with RangeMatcher" do
|
74
|
+
it "returns true" do
|
75
|
+
expectation.should be_terminal
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation, " with failure" do
|
6
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
7
|
+
attr_reader :times, :matcher
|
8
|
+
|
9
|
+
before do
|
10
|
+
@times = 0
|
11
|
+
@matcher = TimesCalledMatchers::IntegerMatcher.new(times)
|
12
|
+
@expectation = TimesCalledExpectation.new(scenario, matcher)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#attempt!" do
|
16
|
+
it "raises error that includes the scenario" do
|
17
|
+
proc do
|
18
|
+
expectation.attempt!
|
19
|
+
end.should raise_error(
|
20
|
+
Errors::TimesCalledError,
|
21
|
+
"#{scenario.formatted_name}\n#{matcher.error_message(1)}"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#verify!" do
|
27
|
+
it "raises error with passed in message prepended" do
|
28
|
+
expectation.instance_variable_set(:@times_called, 1)
|
29
|
+
proc do
|
30
|
+
expectation.verify!
|
31
|
+
end.should raise_error(
|
32
|
+
Errors::TimesCalledError,
|
33
|
+
"#{scenario.formatted_name}\n#{matcher.error_message(1)}"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe Rspec do
|
6
|
+
describe "#setup_mocks_for_rspec" do
|
7
|
+
before do
|
8
|
+
@fixture = Object.new
|
9
|
+
@fixture.extend Rspec
|
10
|
+
|
11
|
+
@subject = Object.new
|
12
|
+
@method_name = :foobar
|
13
|
+
end
|
14
|
+
|
15
|
+
it "resets the double_insertions" do
|
16
|
+
RR::Space.double_insertion(@subject, @method_name)
|
17
|
+
RR::Space.double_insertions.should_not be_empty
|
18
|
+
|
19
|
+
@fixture.setup_mocks_for_rspec
|
20
|
+
RR::Space.double_insertions.should be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#verify_mocks_for_rspec" do
|
25
|
+
before do
|
26
|
+
@fixture = Object.new
|
27
|
+
@fixture.extend Rspec
|
28
|
+
|
29
|
+
@subject = Object.new
|
30
|
+
@method_name = :foobar
|
31
|
+
end
|
32
|
+
|
33
|
+
it "verifies the double_insertions" do
|
34
|
+
double_insertion = RR::Space.double_insertion(@subject, @method_name)
|
35
|
+
scenario = RR::Space.scenario(double_insertion)
|
36
|
+
|
37
|
+
scenario.once
|
38
|
+
|
39
|
+
proc do
|
40
|
+
@fixture.verify_mocks_for_rspec
|
41
|
+
end.should raise_error(::RR::Errors::TimesCalledError)
|
42
|
+
RR::Space.double_insertions.should be_empty
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#teardown_mocks_for_rspec" do
|
47
|
+
before do
|
48
|
+
@fixture = Object.new
|
49
|
+
@fixture.extend Rspec
|
50
|
+
|
51
|
+
@subject = Object.new
|
52
|
+
@method_name = :foobar
|
53
|
+
end
|
54
|
+
|
55
|
+
it "resets the double_insertions" do
|
56
|
+
RR::Space.double_insertion(@subject, @method_name)
|
57
|
+
RR::Space.double_insertions.should_not be_empty
|
58
|
+
|
59
|
+
@fixture.teardown_mocks_for_rspec
|
60
|
+
RR::Space.double_insertions.should be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe Rspec do
|
6
|
+
describe "#trim_backtrace" do
|
7
|
+
it "does not set trim_backtrace" do
|
8
|
+
RR::Space.trim_backtrace.should == false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".included" do
|
13
|
+
it "does not add backtrace identifier twice" do
|
14
|
+
length = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.length
|
15
|
+
class << Object.new
|
16
|
+
include ::RR::Adapters::Rspec
|
17
|
+
end
|
18
|
+
::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.length.should == length
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe " backtrace tweaking" do
|
23
|
+
attr_reader :original_rspec_options, :output
|
24
|
+
before do
|
25
|
+
@original_rspec_options = $rspec_options
|
26
|
+
@output = StringIO.new("")
|
27
|
+
$rspec_options = ::Spec::Runner::Options.new(output, StringIO.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
$rspec_options = original_rspec_options
|
32
|
+
end
|
33
|
+
|
34
|
+
it "hides rr library from the backtrace by default" do
|
35
|
+
subject = @subject
|
36
|
+
Class.new(::Spec::Example::ExampleGroup) do
|
37
|
+
describe "Example"
|
38
|
+
|
39
|
+
it("hides RR framework in backtrace") do
|
40
|
+
mock(subject).foobar()
|
41
|
+
RR::Space::instance.verify_double(subject, :foobar)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
$rspec_options.run_examples
|
46
|
+
|
47
|
+
output.string.should_not include("lib/rr")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
describe RR do
|
4
|
+
describe "#mock" do
|
5
|
+
before do
|
6
|
+
@subject = Object.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "creates a mock DoubleInsertion Double" do
|
10
|
+
mock(@subject).foobar(1, 2) {:baz}
|
11
|
+
@subject.foobar(1, 2).should == :baz
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#stub" do
|
16
|
+
before do
|
17
|
+
@subject = Object.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates a stub DoubleInsertion Double" do
|
21
|
+
stub(@subject).foobar {:baz}
|
22
|
+
@subject.foobar("any", "thing").should == :baz
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#mock and #proxy" do
|
27
|
+
before do
|
28
|
+
@subject = Object.new
|
29
|
+
def @subject.foobar
|
30
|
+
:baz
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "creates a proxy DoubleInsertion Double" do
|
35
|
+
mock.proxy(@subject).foobar
|
36
|
+
@subject.foobar.should == :baz
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#stub and #proxy" do
|
41
|
+
before do
|
42
|
+
@subject = Object.new
|
43
|
+
def @subject.foobar
|
44
|
+
:baz
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates a proxy DoubleInsertion Double" do
|
49
|
+
stub.proxy(@subject).foobar
|
50
|
+
@subject.foobar.should == :baz
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#stub and #proxy" do
|
55
|
+
before do
|
56
|
+
@subject = Object.new
|
57
|
+
def @subject.foobar
|
58
|
+
:baz
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "creates a proxy DoubleInsertion Double" do
|
63
|
+
stub.proxy(@subject).foobar
|
64
|
+
@subject.foobar.should == :baz
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
describe HashWithObjectIdKey do
|
5
|
+
describe "#[] and #[]=" do
|
6
|
+
it "stores object via object id" do
|
7
|
+
hash = HashWithObjectIdKey.new
|
8
|
+
array_1 = []
|
9
|
+
hash[array_1] = 1
|
10
|
+
array_2 = []
|
11
|
+
hash[array_2] = 2
|
12
|
+
|
13
|
+
hash[array_1].should_not == hash[array_2]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "stores the passed in object" do
|
17
|
+
hash = HashWithObjectIdKey.new
|
18
|
+
obj = Object.new
|
19
|
+
hash[obj] = 1
|
20
|
+
hash.instance_eval {@keys}.should == {obj.__id__ => obj}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#each" do
|
25
|
+
it "iterates through the items in the hash" do
|
26
|
+
hash = HashWithObjectIdKey.new
|
27
|
+
hash['one'] = 1
|
28
|
+
hash['two'] = 2
|
29
|
+
|
30
|
+
keys = []
|
31
|
+
values = []
|
32
|
+
hash.each do |key, value|
|
33
|
+
keys << key
|
34
|
+
values << value
|
35
|
+
end
|
36
|
+
|
37
|
+
keys.sort.should == ['one', 'two']
|
38
|
+
values.sort.should == [1, 2]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#delete" do
|
43
|
+
before do
|
44
|
+
@hash = HashWithObjectIdKey.new
|
45
|
+
@key = Object.new
|
46
|
+
@hash[@key] = 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it "removes the object from the hash" do
|
50
|
+
@hash.delete(@key)
|
51
|
+
@hash[@key].should == {}
|
52
|
+
end
|
53
|
+
|
54
|
+
it "removes the object from the keys hash" do
|
55
|
+
@hash.delete(@key)
|
56
|
+
@hash.instance_eval {@keys}.should == {}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#keys" do
|
61
|
+
before do
|
62
|
+
@hash = HashWithObjectIdKey.new
|
63
|
+
@key = Object.new
|
64
|
+
@hash[@key] = 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns an array of the keys" do
|
68
|
+
@hash.keys.should == [@key]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#include?" do
|
73
|
+
before do
|
74
|
+
@hash = HashWithObjectIdKey.new
|
75
|
+
@key = Object.new
|
76
|
+
@hash[@key] = 1
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns true when the key is in the Hash" do
|
80
|
+
@hash.should include(@key)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns false when the key is not in the Hash" do
|
84
|
+
@hash.should_not include(Object.new)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
describe Space, "#scenario_method_proxy", :shared => true do
|
5
|
+
it_should_behave_like "RR::Space"
|
6
|
+
|
7
|
+
before do
|
8
|
+
@space = Space.new
|
9
|
+
@object = Object.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "creates a DoubleMethodProxy" do
|
13
|
+
proxy = @space.scenario_method_proxy(@creator, @object)
|
14
|
+
proxy.should be_instance_of(DoubleMethodProxy)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets space to self" do
|
18
|
+
proxy = @space.scenario_method_proxy(@creator, @object)
|
19
|
+
class << proxy
|
20
|
+
attr_reader :space
|
21
|
+
end
|
22
|
+
proxy.space.should === @space
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets creator to passed in creator" do
|
26
|
+
proxy = @space.scenario_method_proxy(@creator, @object)
|
27
|
+
class << proxy
|
28
|
+
attr_reader :creator
|
29
|
+
end
|
30
|
+
proxy.creator.should === @creator
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises error if passed a method name and a block" do
|
34
|
+
proc do
|
35
|
+
@space.scenario_method_proxy(@creator, @object, :foobar) {}
|
36
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Space, "#scenario_method_proxy with a Mock strategy" do
|
41
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
42
|
+
|
43
|
+
before do
|
44
|
+
@creator = @space.scenario_creator
|
45
|
+
@creator.mock
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates a mock Double for method when passed a second argument" do
|
49
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
50
|
+
@object.foobar(1).should == :baz
|
51
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "uses block definition when passed a block" do
|
55
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
56
|
+
c.foobar(1) {:baz}
|
57
|
+
end
|
58
|
+
@object.foobar(1).should == :baz
|
59
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe Space, "#scenario_method_proxy with a Stub strategy" do
|
64
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
65
|
+
|
66
|
+
before do
|
67
|
+
@creator = @space.scenario_creator
|
68
|
+
@creator.stub
|
69
|
+
end
|
70
|
+
|
71
|
+
it "creates a stub Double for method when passed a second argument" do
|
72
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
73
|
+
@object.foobar(1).should == :baz
|
74
|
+
@object.foobar(1).should == :baz
|
75
|
+
end
|
76
|
+
|
77
|
+
it "uses block definition when passed a block" do
|
78
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
79
|
+
c.foobar(1) {:return_value}
|
80
|
+
c.foobar.with_any_args {:default}
|
81
|
+
c.baz(1) {:baz_value}
|
82
|
+
end
|
83
|
+
@object.foobar(1).should == :return_value
|
84
|
+
@object.foobar.should == :default
|
85
|
+
proc {@object.baz.should == :return_value}.should raise_error
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe Space, "#scenario_method_proxy with a Mock Proxy strategy" do
|
90
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
91
|
+
|
92
|
+
before do
|
93
|
+
@creator = @space.scenario_creator
|
94
|
+
@creator.mock.proxy
|
95
|
+
def @object.foobar(*args)
|
96
|
+
:original_foobar
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it "creates a mock proxy Double for method when passed a second argument" do
|
101
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1)
|
102
|
+
@object.foobar(1).should == :original_foobar
|
103
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "uses block definition when passed a block" do
|
107
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
108
|
+
c.foobar(1)
|
109
|
+
end
|
110
|
+
@object.foobar(1).should == :original_foobar
|
111
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe Space, "#scenario_method_proxy with a Stub proxy strategy" do
|
116
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
117
|
+
|
118
|
+
before do
|
119
|
+
@creator = @space.scenario_creator
|
120
|
+
@creator.stub.proxy
|
121
|
+
def @object.foobar(*args)
|
122
|
+
:original_foobar
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "creates a stub proxy Double for method when passed a second argument" do
|
127
|
+
@space.scenario_method_proxy(@creator, @object, :foobar)
|
128
|
+
@object.foobar(1).should == :original_foobar
|
129
|
+
@object.foobar(1).should == :original_foobar
|
130
|
+
end
|
131
|
+
|
132
|
+
it "uses block definition when passed a block" do
|
133
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
134
|
+
c.foobar(1)
|
135
|
+
end
|
136
|
+
@object.foobar(1).should == :original_foobar
|
137
|
+
@object.foobar(1).should == :original_foobar
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe Space, "#scenario_method_proxy with a Do Not Allow strategy" do
|
142
|
+
it_should_behave_like "RR::Space#scenario_method_proxy"
|
143
|
+
|
144
|
+
before do
|
145
|
+
@creator = @space.scenario_creator
|
146
|
+
@creator.dont_allow
|
147
|
+
end
|
148
|
+
|
149
|
+
it "creates a do not allow Double for method when passed a second argument" do
|
150
|
+
@space.scenario_method_proxy(@creator, @object, :foobar).with(1)
|
151
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "uses block definition when passed a block" do
|
155
|
+
@space.scenario_method_proxy(@creator, @object) do |c|
|
156
|
+
c.foobar(1)
|
157
|
+
end
|
158
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe Space, "#scenario_creator" do
|
163
|
+
it_should_behave_like "RR::Space"
|
164
|
+
|
165
|
+
before do
|
166
|
+
@space = Space.new
|
167
|
+
@object = Object.new
|
168
|
+
@creator = @space.scenario_creator
|
169
|
+
end
|
170
|
+
|
171
|
+
it "sets the space" do
|
172
|
+
@creator.space.should === @space
|
173
|
+
end
|
174
|
+
|
175
|
+
it "creates a DoubleCreator" do
|
176
|
+
@creator.should be_instance_of(DoubleCreator)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe Space, "#scenario" do
|
181
|
+
it_should_behave_like "RR::Space"
|
182
|
+
|
183
|
+
before do
|
184
|
+
@space = Space.new
|
185
|
+
@object = Object.new
|
186
|
+
@method_name = :foobar
|
187
|
+
end
|
188
|
+
|
189
|
+
it "creates a Double and registers it to the double_insertion" do
|
190
|
+
double_insertion = @space.double_insertion(@object, @method_name)
|
191
|
+
def double_insertion.scenarios
|
192
|
+
@scenarios
|
193
|
+
end
|
194
|
+
|
195
|
+
scenario = @space.scenario(double_insertion)
|
196
|
+
double_insertion.scenarios.should include(scenario)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe Space, "#double_insertion" do
|
201
|
+
it_should_behave_like "RR::Space"
|
202
|
+
|
203
|
+
before do
|
204
|
+
@space = Space.new
|
205
|
+
end
|
206
|
+
|
207
|
+
it "creates a new double_insertion when existing object == but not === with the same method name" do
|
208
|
+
object1 = []
|
209
|
+
object2 = []
|
210
|
+
(object1 === object2).should be_true
|
211
|
+
object1.__id__.should_not == object2.__id__
|
212
|
+
|
213
|
+
double1 = @space.double_insertion(object1, :foobar)
|
214
|
+
double2 = @space.double_insertion(object2, :foobar)
|
215
|
+
|
216
|
+
double1.should_not == double2
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe Space, "#double_insertion when double_insertion does not exist" do
|
221
|
+
it_should_behave_like "RR::Space"
|
222
|
+
|
223
|
+
before do
|
224
|
+
@space = Space.new
|
225
|
+
@object = Object.new
|
226
|
+
def @object.foobar(*args)
|
227
|
+
:original_foobar
|
228
|
+
end
|
229
|
+
@method_name = :foobar
|
230
|
+
end
|
231
|
+
|
232
|
+
it "returns double_insertion and adds double_insertion to double_insertion list when method_name is a symbol" do
|
233
|
+
double_insertion = @space.double_insertion(@object, @method_name)
|
234
|
+
@space.double_insertion(@object, @method_name).should === double_insertion
|
235
|
+
double_insertion.space.should === @space
|
236
|
+
double_insertion.object.should === @object
|
237
|
+
double_insertion.method_name.should === @method_name
|
238
|
+
end
|
239
|
+
|
240
|
+
it "returns double_insertion and adds double_insertion to double_insertion list when method_name is a string" do
|
241
|
+
double_insertion = @space.double_insertion(@object, 'foobar')
|
242
|
+
@space.double_insertion(@object, @method_name).should === double_insertion
|
243
|
+
double_insertion.space.should === @space
|
244
|
+
double_insertion.object.should === @object
|
245
|
+
double_insertion.method_name.should === @method_name
|
246
|
+
end
|
247
|
+
|
248
|
+
it "overrides the method when passing a block" do
|
249
|
+
double_insertion = @space.double_insertion(@object, @method_name)
|
250
|
+
@object.methods.should include("__rr__#{@method_name}")
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe Space, "#double_insertion when double_insertion exists" do
|
255
|
+
it_should_behave_like "RR::Space"
|
256
|
+
|
257
|
+
before do
|
258
|
+
@space = Space.new
|
259
|
+
@object = Object.new
|
260
|
+
def @object.foobar(*args)
|
261
|
+
:original_foobar
|
262
|
+
end
|
263
|
+
@method_name = :foobar
|
264
|
+
end
|
265
|
+
|
266
|
+
it "returns the existing double_insertion" do
|
267
|
+
original_foobar_method = @object.method(:foobar)
|
268
|
+
double_insertion = @space.double_insertion(@object, 'foobar')
|
269
|
+
|
270
|
+
double_insertion.object_has_original_method?.should be_true
|
271
|
+
|
272
|
+
@space.double_insertion(@object, 'foobar').should === double_insertion
|
273
|
+
|
274
|
+
double_insertion.reset
|
275
|
+
@object.foobar.should == :original_foobar
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|