rspec 0.8.2 → 0.9.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 +125 -9
- data/EXAMPLES.rd +50 -27
- data/README +14 -1
- data/Rakefile +95 -42
- data/UPGRADE +31 -0
- data/bin/spec +0 -1
- data/bin/spec_translator +6 -0
- data/examples/auto_spec_description_example.rb +19 -0
- data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
- data/examples/behave_as_example.rb +45 -0
- data/examples/custom_expectation_matchers.rb +13 -12
- data/examples/dynamic_spec.rb +2 -2
- data/examples/file_accessor_spec.rb +2 -2
- data/examples/greeter_spec.rb +3 -3
- data/examples/helper_method_example.rb +2 -2
- data/examples/io_processor_spec.rb +4 -4
- data/examples/legacy_spec.rb +10 -0
- data/examples/mocking_example.rb +5 -5
- data/examples/multi_threaded_behaviour_runner.rb +25 -0
- data/examples/partial_mock_example.rb +4 -4
- data/examples/predicate_example.rb +4 -4
- data/examples/priority.txt +1 -0
- data/examples/shared_behaviours_example.rb +31 -0
- data/examples/stack_spec.rb +52 -69
- data/examples/stubbing_example.rb +10 -10
- data/examples/test_case_adapter_example.rb +26 -0
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +9 -4
- data/lib/spec/dsl.rb +10 -0
- data/lib/spec/dsl/behaviour.rb +189 -0
- data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
- data/lib/spec/dsl/behaviour_eval.rb +170 -0
- data/lib/spec/dsl/behaviour_factory.rb +32 -0
- data/lib/spec/dsl/composite_proc_builder.rb +28 -0
- data/lib/spec/dsl/configuration.rb +38 -0
- data/lib/spec/dsl/description.rb +34 -0
- data/lib/spec/dsl/example.rb +114 -0
- data/lib/spec/dsl/example_matcher.rb +28 -0
- data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
- data/lib/spec/expectations.rb +0 -3
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/extensions/object.rb +10 -53
- data/lib/spec/expectations/handler.rb +14 -18
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/object.rb +6 -0
- data/lib/spec/matchers.rb +19 -21
- data/lib/spec/matchers/be.rb +40 -11
- data/lib/spec/matchers/be_close.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +52 -0
- data/lib/spec/matchers/respond_to.rb +21 -11
- data/lib/spec/mocks.rb +5 -28
- data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
- data/lib/spec/mocks/argument_expectation.rb +7 -4
- data/lib/spec/mocks/methods.rb +11 -16
- data/lib/spec/mocks/mock.rb +6 -3
- data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +30 -0
- data/lib/spec/rake/spectask.rb +23 -21
- data/lib/spec/rake/verify_rcov.rb +1 -0
- data/lib/spec/runner.rb +88 -35
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/behaviour_runner.rb +102 -0
- data/lib/spec/runner/command_line.rb +5 -17
- data/lib/spec/runner/drb_command_line.rb +2 -2
- data/lib/spec/runner/extensions/kernel.rb +22 -9
- data/lib/spec/runner/formatter.rb +4 -0
- data/lib/spec/runner/formatter/base_formatter.rb +63 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
- data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
- data/lib/spec/runner/formatter/html_formatter.rb +74 -29
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
- data/lib/spec/runner/heckle_runner.rb +8 -7
- data/lib/spec/runner/option_parser.rb +136 -55
- data/lib/spec/runner/options.rb +26 -0
- data/lib/spec/runner/reporter.rb +38 -31
- data/lib/spec/runner/spec_parser.rb +22 -13
- data/lib/spec/test_case_adapter.rb +10 -0
- data/lib/spec/translator.rb +103 -86
- data/lib/spec/version.rb +7 -15
- data/plugins/mock_frameworks/flexmock.rb +27 -0
- data/plugins/mock_frameworks/mocha.rb +21 -0
- data/plugins/mock_frameworks/rspec.rb +18 -0
- data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
- data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
- data/spec/spec/dsl/behaviour_spec.rb +508 -0
- data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
- data/spec/spec/dsl/configuration_spec.rb +43 -0
- data/spec/spec/dsl/description_spec.rb +51 -0
- data/spec/spec/dsl/example_class_spec.rb +24 -0
- data/spec/spec/dsl/example_instance_spec.rb +140 -0
- data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
- data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
- data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
- data/spec/spec/expectations/differs/default_spec.rb +12 -12
- data/spec/spec/expectations/extensions/object_spec.rb +10 -10
- data/spec/spec/expectations/fail_with_spec.rb +20 -20
- data/spec/spec/matchers/be_close_spec.rb +37 -31
- data/spec/spec/matchers/be_spec.rb +50 -41
- data/spec/spec/matchers/change_spec.rb +54 -54
- data/spec/spec/matchers/description_generation_spec.rb +43 -31
- data/spec/spec/matchers/eql_spec.rb +24 -37
- data/spec/spec/matchers/equal_spec.rb +24 -37
- data/spec/spec/matchers/exist_spec.rb +48 -0
- data/spec/spec/matchers/handler_spec.rb +36 -23
- data/spec/spec/matchers/has_spec.rb +8 -8
- data/spec/spec/matchers/have_spec.rb +38 -38
- data/spec/spec/matchers/include_spec.rb +6 -6
- data/spec/spec/matchers/match_spec.rb +8 -8
- data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
- data/spec/spec/matchers/raise_error_spec.rb +34 -34
- data/spec/spec/matchers/respond_to_spec.rb +32 -8
- data/spec/spec/matchers/satisfy_spec.rb +6 -6
- data/spec/spec/matchers/should_===_spec.rb +38 -0
- data/spec/spec/matchers/should_==_spec.rb +37 -0
- data/spec/spec/matchers/should_=~_spec.rb +36 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
- data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
- data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/spec/mocks/at_least_spec.rb +30 -30
- data/spec/spec/mocks/at_most_spec.rb +53 -57
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
- data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
- data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +111 -141
- data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
- data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
- data/spec/spec/mocks/once_counts_spec.rb +32 -35
- data/spec/spec/mocks/options_hash_spec.rb +12 -10
- data/spec/spec/mocks/partial_mock_spec.rb +15 -15
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
- data/spec/spec/mocks/precise_counts_spec.rb +28 -32
- data/spec/spec/mocks/record_messages_spec.rb +10 -10
- data/spec/spec/mocks/stub_spec.rb +45 -45
- data/spec/spec/mocks/twice_counts_spec.rb +21 -21
- data/spec/spec/package/bin_spec_spec.rb +12 -0
- data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
- data/spec/spec/runner/command_line_spec.rb +8 -8
- data/spec/spec/runner/context_matching_spec.rb +14 -15
- data/spec/spec/runner/drb_command_line_spec.rb +12 -12
- data/spec/spec/runner/execution_context_spec.rb +8 -29
- data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
- data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
- data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
- data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/heckle_runner_spec.rb +21 -21
- data/spec/spec/runner/heckler_spec.rb +5 -5
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
- data/spec/spec/runner/object_ext_spec.rb +3 -3
- data/spec/spec/runner/option_parser_spec.rb +171 -102
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
- data/spec/spec/runner/reporter_spec.rb +106 -97
- data/spec/spec/runner/spec_matcher_spec.rb +46 -51
- data/spec/spec/runner/spec_parser_spec.rb +72 -16
- data/spec/spec/spec_classes.rb +12 -3
- data/spec/spec/translator_spec.rb +165 -36
- metadata +66 -76
- data/RELEASE-PLAN +0 -117
- data/examples/auto_spec_name_generation_example.rb +0 -18
- data/lib/spec/callback.rb +0 -11
- data/lib/spec/callback/callback_container.rb +0 -60
- data/lib/spec/callback/extensions/module.rb +0 -24
- data/lib/spec/callback/extensions/object.rb +0 -37
- data/lib/spec/deprecated.rb +0 -3
- data/lib/spec/expectations/extensions/proc.rb +0 -57
- data/lib/spec/expectations/should.rb +0 -5
- data/lib/spec/expectations/should/base.rb +0 -64
- data/lib/spec/expectations/should/change.rb +0 -69
- data/lib/spec/expectations/should/have.rb +0 -128
- data/lib/spec/expectations/should/not.rb +0 -74
- data/lib/spec/expectations/should/should.rb +0 -81
- data/lib/spec/expectations/sugar.rb +0 -47
- data/lib/spec/runner/context.rb +0 -154
- data/lib/spec/runner/context_eval.rb +0 -142
- data/lib/spec/runner/context_runner.rb +0 -55
- data/lib/spec/runner/execution_context.rb +0 -17
- data/lib/spec/runner/spec_matcher.rb +0 -25
- data/lib/spec/runner/specification.rb +0 -114
- data/spec/spec/callback/callback_container_spec.rb +0 -27
- data/spec/spec/callback/module_spec.rb +0 -37
- data/spec/spec/callback/object_spec.rb +0 -90
- data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
- data/spec/spec/expectations/should/should_==_spec.rb +0 -19
- data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
- data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
- data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
- data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
- data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
- data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
- data/spec/spec/expectations/should/should_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
- data/spec/spec/expectations/should/should_change_spec.rb +0 -184
- data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
- data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
- data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
- data/spec/spec/expectations/should/should_have_spec.rb +0 -64
- data/spec/spec/expectations/should/should_include_spec.rb +0 -59
- data/spec/spec/expectations/should/should_match_spec.rb +0 -25
- data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
- data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
- data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
- data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
- data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
- data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
- data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
- data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
- data/spec/spec/runner/context_runner_spec.rb +0 -100
- data/spec/spec/runner/context_spec.rb +0 -405
- data/spec/spec/runner/kernel_ext_spec.rb +0 -16
- data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
- data/spec/spec/runner/specification_class_spec.rb +0 -72
- data/spec/spec/runner/specification_instance_spec.rb +0 -160
- data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
module Spec
|
|
4
|
+
module DSL
|
|
5
|
+
class Fish
|
|
6
|
+
def can_swim?(distance_in_yards)
|
|
7
|
+
distance_in_yards < 1000
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "predicate_matcher[method_on_object] = matcher_method" do
|
|
12
|
+
predicate_matchers[:can_swim?] = :swim
|
|
13
|
+
it "should match matcher_method if method_on_object returns true" do
|
|
14
|
+
swim(100).matches?(Fish.new).should be_true
|
|
15
|
+
end
|
|
16
|
+
it "should not match matcher_method if method_on_object returns false" do
|
|
17
|
+
swim(10000).matches?(Fish.new).should be_false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
module Spec
|
|
4
|
+
module DSL
|
|
5
|
+
describe Behaviour, ", with :shared => true" do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
|
|
9
|
+
@behaviour = behaviour_class.new("context") {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after do
|
|
13
|
+
@formatter.rspec_verify
|
|
14
|
+
@behaviour_class = nil
|
|
15
|
+
$shared_behaviours.clear unless $shared_behaviours.nil?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def behaviour_class
|
|
19
|
+
unless @behaviour_class
|
|
20
|
+
@behaviour_class = Behaviour.dup
|
|
21
|
+
# dup copies the class instance vars
|
|
22
|
+
@behaviour_class.instance_variable_set(:@shared_behaviours, nil)
|
|
23
|
+
end
|
|
24
|
+
@behaviour_class
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def make_shared_behaviour(name, opts, &block)
|
|
28
|
+
behaviour = behaviour_class.new(name, opts, &block)
|
|
29
|
+
behaviour_class.add_shared_behaviour(behaviour)
|
|
30
|
+
behaviour
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should accept an optional options hash" do
|
|
34
|
+
lambda { behaviour_class.new("context") {} }.should_not raise_error(Exception)
|
|
35
|
+
lambda { behaviour_class.new("context", :shared => true) {} }.should_not raise_error(Exception)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should return all shared behaviours" do
|
|
39
|
+
make_shared_behaviour("b1", :shared => true) {}
|
|
40
|
+
make_shared_behaviour("b2", :shared => true) {}
|
|
41
|
+
|
|
42
|
+
behaviour_class.find_shared_behaviour("b1").should_not be_nil
|
|
43
|
+
behaviour_class.find_shared_behaviour("b2").should_not be_nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should be shared when configured as shared" do
|
|
47
|
+
behaviour = make_shared_behaviour("context", :shared => true) {}
|
|
48
|
+
behaviour.should be_shared
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should not be shared when not configured as shared" do
|
|
52
|
+
@behaviour.should_not be_shared
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should not run when shared" do
|
|
56
|
+
behaviour = make_shared_behaviour("context", :shared => true) {}
|
|
57
|
+
$spec_ran = false
|
|
58
|
+
behaviour.it("test") {$spec_ran = true}
|
|
59
|
+
behaviour.run(@formatter)
|
|
60
|
+
$spec_ran.should be_false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should contain examples when shared" do
|
|
64
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
65
|
+
shared_behaviour.it("shared example") {}
|
|
66
|
+
shared_behaviour.number_of_examples.should == 1
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should complain when adding a shared behaviour with the same description" do
|
|
70
|
+
make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
71
|
+
lambda { make_shared_behaviour("shared behaviour", :shared => true) {} }.should raise_error(ArgumentError)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should add examples to current behaviour when calling it_should_behave_like" do
|
|
75
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
76
|
+
shared_behaviour.it("shared example") {}
|
|
77
|
+
shared_behaviour.it("shared example 2") {}
|
|
78
|
+
|
|
79
|
+
@behaviour.it("example") {}
|
|
80
|
+
@behaviour.number_of_examples.should == 1
|
|
81
|
+
@behaviour.it_should_behave_like("shared behaviour")
|
|
82
|
+
@behaviour.number_of_examples.should == 3
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should run shared examples" do
|
|
86
|
+
shared_example_ran = false
|
|
87
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
88
|
+
shared_behaviour.it("shared example") { shared_example_ran = true }
|
|
89
|
+
|
|
90
|
+
example_ran = false
|
|
91
|
+
|
|
92
|
+
@behaviour.it_should_behave_like("shared behaviour")
|
|
93
|
+
@behaviour.it("example") {example_ran = true}
|
|
94
|
+
@behaviour.run(@formatter)
|
|
95
|
+
example_ran.should be_true
|
|
96
|
+
shared_example_ran.should be_true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should run setup and teardown from shared behaviour" do
|
|
100
|
+
shared_setup_ran = false
|
|
101
|
+
shared_teardown_ran = false
|
|
102
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
103
|
+
shared_behaviour.before { shared_setup_ran = true }
|
|
104
|
+
shared_behaviour.after { shared_teardown_ran = true }
|
|
105
|
+
shared_behaviour.it("shared example") { shared_example_ran = true }
|
|
106
|
+
|
|
107
|
+
example_ran = false
|
|
108
|
+
|
|
109
|
+
@behaviour.it_should_behave_like("shared behaviour")
|
|
110
|
+
@behaviour.it("example") {example_ran = true}
|
|
111
|
+
@behaviour.run(@formatter)
|
|
112
|
+
example_ran.should be_true
|
|
113
|
+
shared_setup_ran.should be_true
|
|
114
|
+
shared_teardown_ran.should be_true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should run before(:all) and after(:all) only once from shared behaviour" do
|
|
118
|
+
shared_before_all_run_count = 0
|
|
119
|
+
shared_after_all_run_count = 0
|
|
120
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
121
|
+
shared_behaviour.before(:all) { shared_before_all_run_count += 1}
|
|
122
|
+
shared_behaviour.after(:all) { shared_after_all_run_count += 1}
|
|
123
|
+
shared_behaviour.it("shared example") { shared_example_ran = true }
|
|
124
|
+
|
|
125
|
+
example_ran = false
|
|
126
|
+
|
|
127
|
+
@behaviour.it_should_behave_like("shared behaviour")
|
|
128
|
+
@behaviour.it("example") {example_ran = true}
|
|
129
|
+
@behaviour.run(@formatter)
|
|
130
|
+
example_ran.should be_true
|
|
131
|
+
shared_before_all_run_count.should == 1
|
|
132
|
+
shared_after_all_run_count.should == 1
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should include modules, included into shared behaviour, into current behaviour" do
|
|
136
|
+
@formatter.should_receive(:add_behaviour).with :any_args
|
|
137
|
+
@formatter.should_receive(:example_finished).twice.with :any_args
|
|
138
|
+
|
|
139
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
140
|
+
shared_behaviour.it("shared example") { shared_example_ran = true }
|
|
141
|
+
|
|
142
|
+
mod1_method_called = false
|
|
143
|
+
mod1 = Module.new do
|
|
144
|
+
define_method :mod1_method do
|
|
145
|
+
mod1_method_called = true
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
mod2_method_called = false
|
|
150
|
+
mod2 = Module.new do
|
|
151
|
+
define_method :mod2_method do
|
|
152
|
+
mod2_method_called = true
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
shared_behaviour.include mod2
|
|
157
|
+
|
|
158
|
+
@behaviour.it_should_behave_like("shared behaviour")
|
|
159
|
+
@behaviour.include mod1
|
|
160
|
+
|
|
161
|
+
@behaviour.it("test") do
|
|
162
|
+
mod1_method
|
|
163
|
+
mod2_method
|
|
164
|
+
end
|
|
165
|
+
@behaviour.run(@formatter)
|
|
166
|
+
mod1_method_called.should be_true
|
|
167
|
+
mod2_method_called.should be_true
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should error if told to inherit from a class" do
|
|
171
|
+
shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
|
|
172
|
+
shared_behaviour.it("shared example") { shared_example_ran = true }
|
|
173
|
+
lambda { shared_behaviour.inherit Object }.should raise_error(ArgumentError)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "should raise when named shared behaviour can not be found" do
|
|
177
|
+
begin
|
|
178
|
+
@behaviour.it_should_behave_like("non-existent shared behaviour")
|
|
179
|
+
violated
|
|
180
|
+
rescue => e
|
|
181
|
+
e.message.should == "Shared Behaviour 'non-existent shared behaviour' can not be found"
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
@@ -20,20 +20,20 @@ module Spec
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
describe "Diff" do
|
|
24
|
+
before(:each) do
|
|
25
25
|
@differ = Spec::Expectations::Differs::Default.new
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
it "should output unified diff of two strings" do
|
|
29
29
|
expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
|
|
30
30
|
actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
|
|
31
31
|
expected_diff="\n\n@@ -1,6 +1,6 @@\n foo\n-bar\n zap\n+bar\n this\n is\n soo\n@@ -9,5 +9,6 @@\n equal\n insert\n a\n+another\n line\n"
|
|
32
32
|
diff = @differ.diff_as_string(expected, actual)
|
|
33
|
-
diff.
|
|
33
|
+
diff.should eql(expected_diff)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
it "should output unified diff message of two arrays" do
|
|
37
37
|
expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
|
|
38
38
|
actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
|
|
39
39
|
|
|
@@ -53,10 +53,10 @@ EOD
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
diff = @differ.diff_as_object(expected,actual)
|
|
56
|
-
diff.
|
|
56
|
+
diff.should == expected_diff
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
it "should output unified diff message of two objects" do
|
|
60
60
|
expected = Spec::Fixtures::Animal.new "bob", "giraffe"
|
|
61
61
|
actual = Spec::Fixtures::Animal.new "bob", "tortoise"
|
|
62
62
|
|
|
@@ -71,18 +71,18 @@ EOD
|
|
|
71
71
|
EOD
|
|
72
72
|
|
|
73
73
|
diff = @differ.diff_as_object(expected,actual)
|
|
74
|
-
diff.
|
|
74
|
+
diff.should == expected_diff
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
describe "Diff in context format" do
|
|
81
|
+
before(:each) do
|
|
82
82
|
@differ = Spec::Expectations::Differs::Default.new(:context)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
it "should output unified diff message of two objects" do
|
|
86
86
|
expected = Spec::Fixtures::Animal.new "bob", "giraffe"
|
|
87
87
|
actual = Spec::Fixtures::Animal.new "bob", "tortoise"
|
|
88
88
|
|
|
@@ -102,6 +102,6 @@ context "Diff in context format" do
|
|
|
102
102
|
EOD
|
|
103
103
|
|
|
104
104
|
diff = @differ.diff_as_object(expected,actual)
|
|
105
|
-
diff.
|
|
105
|
+
diff.should == expected_diff
|
|
106
106
|
end
|
|
107
107
|
end
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../../../spec_helper.rb'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
describe "Object#should" do
|
|
4
|
+
before(:each) do
|
|
5
5
|
@target = "target"
|
|
6
6
|
@matcher = mock("matcher")
|
|
7
7
|
@matcher.stub!(:matches?).and_return(true)
|
|
8
8
|
@matcher.stub!(:failure_message)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
it "should accept and interact with a matcher" do
|
|
12
12
|
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
|
13
13
|
|
|
14
14
|
@target.should @matcher
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
it "should ask for a failure_message when matches? returns false" do
|
|
18
18
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
|
19
19
|
@matcher.should_receive(:failure_message).and_return("the failure message")
|
|
20
20
|
lambda {
|
|
21
21
|
@target.should @matcher
|
|
22
|
-
}.
|
|
22
|
+
}.should fail_with("the failure message")
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
describe "Object#should_not" do
|
|
27
|
+
before(:each) do
|
|
28
28
|
@target = "target"
|
|
29
29
|
@matcher = mock("matcher")
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
it "should accept and interact with a matcher" do
|
|
33
33
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
|
34
34
|
@matcher.stub!(:negative_failure_message)
|
|
35
35
|
|
|
36
36
|
@target.should_not @matcher
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
it "should ask for a negative_failure_message when matches? returns true" do
|
|
40
40
|
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
|
41
41
|
@matcher.should_receive(:negative_failure_message).and_return("the negative failure message")
|
|
42
42
|
lambda {
|
|
43
43
|
@target.should_not @matcher
|
|
44
|
-
}.
|
|
44
|
+
}.should fail_with("the negative failure message")
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
describe "Spec::Expectations.fail_with with no diff" do
|
|
4
|
+
before(:each) do
|
|
5
5
|
@old_differ = Spec::Expectations.differ
|
|
6
6
|
Spec::Expectations.differ = nil
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
it "should handle just a message" do
|
|
10
10
|
lambda {
|
|
11
11
|
Spec::Expectations.fail_with "the message"
|
|
12
|
-
}.
|
|
12
|
+
}.should fail_with("the message")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
it "should handle an Array" do
|
|
16
16
|
lambda {
|
|
17
17
|
Spec::Expectations.fail_with ["the message","expected","actual"]
|
|
18
|
-
}.
|
|
18
|
+
}.should fail_with("the message")
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
after(:each) do
|
|
22
22
|
Spec::Expectations.differ = @old_differ
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
describe "Spec::Expectations.fail_with with diff" do
|
|
27
|
+
before(:each) do
|
|
28
28
|
@old_differ = Spec::Expectations.differ
|
|
29
29
|
@differ = mock("differ")
|
|
30
30
|
Spec::Expectations.differ = @differ
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
it "should not call differ if no expected/actual" do
|
|
34
34
|
lambda {
|
|
35
35
|
Spec::Expectations.fail_with "the message"
|
|
36
|
-
}.
|
|
36
|
+
}.should fail_with("the message")
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
it "should call differ if expected/actual are presented separately" do
|
|
40
40
|
@differ.should_receive(:diff_as_string).and_return("diff")
|
|
41
41
|
lambda {
|
|
42
42
|
Spec::Expectations.fail_with "the message", "expected", "actual"
|
|
43
|
-
}.
|
|
43
|
+
}.should fail_with("the message\nDiff:diff")
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
it "should call differ if expected/actual are not strings" do
|
|
47
47
|
@differ.should_receive(:diff_as_object).and_return("diff")
|
|
48
48
|
lambda {
|
|
49
49
|
Spec::Expectations.fail_with "the message", :expected, :actual
|
|
50
|
-
}.
|
|
50
|
+
}.should fail_with("the message\nDiff:diff")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
it "should not call differ if expected or actual are procs" do
|
|
54
54
|
@differ.should_not_receive(:diff_as_string)
|
|
55
55
|
@differ.should_not_receive(:diff_as_object)
|
|
56
56
|
lambda {
|
|
57
57
|
Spec::Expectations.fail_with "the message", lambda {}, lambda {}
|
|
58
|
-
}.
|
|
58
|
+
}.should fail_with("the message")
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
it "should call differ if expected/actual are presented in an Array with message" do
|
|
62
62
|
@differ.should_receive(:diff_as_string).with("actual","expected").and_return("diff")
|
|
63
63
|
lambda {
|
|
64
64
|
Spec::Expectations.fail_with(["the message", "expected", "actual"])
|
|
65
|
-
}.
|
|
65
|
+
}.should fail_with(/the message\nDiff:diff/)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
after(:each) do
|
|
69
69
|
Spec::Expectations.differ = @old_differ
|
|
70
70
|
end
|
|
71
71
|
end
|
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
module Spec
|
|
3
|
+
module Matchers
|
|
4
|
+
describe BeClose do
|
|
5
|
+
it "should match when value == target" do
|
|
6
|
+
BeClose.new(5.0, 0.5).matches?(5.0).should be_true
|
|
7
|
+
end
|
|
8
|
+
it "should match when value < (target + delta)" do
|
|
9
|
+
BeClose.new(5.0, 0.5).matches?(5.49).should be_true
|
|
10
|
+
end
|
|
11
|
+
it "should match when value > (target - delta)" do
|
|
12
|
+
BeClose.new(5.0, 0.5).matches?(4.51).should be_true
|
|
13
|
+
end
|
|
14
|
+
it "should not match when value == (target - delta)" do
|
|
15
|
+
BeClose.new(5.0, 0.5).matches?(4.5).should be_false
|
|
16
|
+
end
|
|
17
|
+
it "should not match when value < (target - delta)" do
|
|
18
|
+
BeClose.new(5.0, 0.5).matches?(4.49).should be_false
|
|
19
|
+
end
|
|
20
|
+
it "should not match when value == (target + delta)" do
|
|
21
|
+
BeClose.new(5.0, 0.5).matches?(5.5).should be_false
|
|
22
|
+
end
|
|
23
|
+
it "should not match when value > (target + delta)" do
|
|
24
|
+
BeClose.new(5.0, 0.5).matches?(5.51).should be_false
|
|
25
|
+
end
|
|
26
|
+
it "should provide a useful failure message" do
|
|
27
|
+
#given
|
|
28
|
+
matcher = BeClose.new(5.0, 0.5)
|
|
29
|
+
#when
|
|
30
|
+
matcher.matches?(5.51)
|
|
31
|
+
#then
|
|
32
|
+
matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
|
|
33
|
+
end
|
|
34
|
+
it "should describe itself" do
|
|
35
|
+
BeClose.new(5.0, 0.5).description.should == "be close to 5.0 (within +- 0.5)"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
6
38
|
end
|
|
7
|
-
|
|
8
|
-
5.49.should be_close(5.0, 0.5)
|
|
9
|
-
end
|
|
10
|
-
specify "should pass if target > expected - delta" do
|
|
11
|
-
4.51.should be_close(5.0, 0.5)
|
|
12
|
-
end
|
|
13
|
-
specify "should fail if target == expected - delta" do
|
|
14
|
-
lambda {
|
|
15
|
-
4.5.should be_close(5.0, 0.5)
|
|
16
|
-
}.should fail_with("expected 5.0 +/- (<0.5), got 4.5")
|
|
17
|
-
end
|
|
18
|
-
specify "should fail if target < expected - delta" do
|
|
19
|
-
lambda {
|
|
20
|
-
4.49.should be_close(5.0, 0.5)
|
|
21
|
-
}.should fail_with("expected 5.0 +/- (<0.5), got 4.49")
|
|
22
|
-
end
|
|
23
|
-
specify "should fail if target == expected + delta" do
|
|
24
|
-
lambda {
|
|
25
|
-
5.5.should be_close(5.0, 0.5)
|
|
26
|
-
}.should fail_with("expected 5.0 +/- (<0.5), got 5.5")
|
|
27
|
-
end
|
|
28
|
-
specify "should fail if target > expected + delta" do
|
|
29
|
-
lambda {
|
|
30
|
-
5.51.should be_close(5.0, 0.5)
|
|
31
|
-
}.should fail_with("expected 5.0 +/- (<0.5), got 5.51")
|
|
32
|
-
end
|
|
33
|
-
end
|
|
39
|
+
end
|