rspec 1.1.4 → 1.1.5
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 → History.txt} +116 -64
- data/Manifest.txt +403 -0
- data/{MIT-LICENSE → README.txt} +43 -0
- data/Rakefile +39 -212
- data/{TODO → TODO.txt} +0 -0
- data/bin/autospec +4 -0
- data/bin/spec +1 -1
- data/examples/pure/yielding_example.rb +33 -0
- data/examples/stories/game-of-life/.loadpath +5 -0
- data/examples/stories/game-of-life/behaviour/everything.rb +1 -1
- data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +17 -17
- data/init.rb +9 -0
- data/lib/autotest/discover.rb +1 -1
- data/lib/autotest/rspec.rb +3 -29
- data/lib/spec.rb +10 -12
- data/lib/spec/adapters.rb +1 -0
- data/lib/spec/adapters/ruby_engine.rb +26 -0
- data/lib/spec/adapters/ruby_engine/mri.rb +8 -0
- data/lib/spec/adapters/ruby_engine/rubinius.rb +8 -0
- data/lib/spec/example/errors.rb +6 -0
- data/lib/spec/example/example_group_methods.rb +17 -14
- data/lib/spec/example/example_matcher.rb +2 -0
- data/lib/spec/example/example_methods.rb +4 -9
- data/lib/spec/example/module_inclusion_warnings.rb +2 -1
- data/lib/spec/expectations/extensions/object.rb +2 -2
- data/lib/spec/expectations/handler.rb +8 -16
- data/lib/spec/extensions/main.rb +2 -17
- data/lib/spec/matchers.rb +8 -2
- data/lib/spec/matchers/be.rb +0 -3
- data/lib/spec/matchers/change.rb +44 -40
- data/lib/spec/matchers/has.rb +1 -1
- data/lib/spec/matchers/have.rb +17 -12
- data/lib/spec/matchers/operator_matcher.rb +10 -4
- data/lib/spec/matchers/simple_matcher.rb +113 -10
- data/lib/spec/mocks.rb +1 -1
- data/lib/spec/mocks/argument_constraints.rb +185 -0
- data/lib/spec/mocks/argument_expectation.rb +35 -173
- data/lib/spec/mocks/framework.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +30 -5
- data/lib/spec/mocks/methods.rb +14 -2
- data/lib/spec/mocks/mock.rb +4 -0
- data/lib/spec/mocks/proxy.rb +46 -5
- data/lib/spec/mocks/spec_methods.rb +9 -1
- data/lib/spec/rake/spectask.rb +14 -22
- data/lib/spec/rake/verify_rcov.rb +3 -3
- data/lib/spec/runner.rb +18 -6
- data/lib/spec/runner/backtrace_tweaker.rb +6 -7
- data/lib/spec/runner/command_line.rb +6 -17
- data/lib/spec/runner/drb_command_line.rb +1 -1
- data/lib/spec/runner/formatter/base_formatter.rb +3 -1
- data/lib/spec/runner/formatter/base_text_formatter.rb +5 -9
- data/lib/spec/runner/formatter/html_formatter.rb +1 -1
- data/lib/spec/runner/formatter/nested_text_formatter.rb +1 -1
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +2 -2
- data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
- data/lib/spec/runner/formatter/story/html_formatter.rb +62 -16
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +68 -16
- data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
- data/lib/spec/runner/heckle_runner.rb +2 -2
- data/lib/spec/runner/option_parser.rb +2 -1
- data/lib/spec/runner/options.rb +18 -9
- data/lib/spec/runner/reporter.rb +24 -4
- data/lib/spec/runner/spec_parser.rb +1 -1
- data/lib/spec/story/runner.rb +1 -2
- data/lib/spec/story/runner/story_mediator.rb +14 -0
- data/lib/spec/story/runner/story_parser.rb +20 -0
- data/lib/spec/story/step.rb +40 -28
- data/lib/spec/story/step_mother.rb +2 -1
- data/lib/spec/story/world.rb +6 -2
- data/lib/spec/version.rb +13 -22
- data/rake_tasks/failing_examples_with_html.rake +1 -1
- data/rake_tasks/verify_rcov.rake +2 -2
- data/rspec.gemspec +33 -0
- data/spec/autotest/rspec_spec.rb +90 -141
- data/spec/spec/adapters/ruby_engine_spec.rb +16 -0
- data/spec/spec/example/base_formatter_spec.rb +112 -0
- data/spec/spec/example/example_group_factory_spec.rb +2 -2
- data/spec/spec/example/example_group_methods_spec.rb +55 -4
- data/spec/spec/example/example_group_spec.rb +4 -3
- data/spec/spec/example/example_methods_spec.rb +18 -14
- data/spec/spec/example/pending_module_spec.rb +38 -0
- data/spec/spec/example/shared_example_group_spec.rb +1 -1
- data/spec/spec/expectations/extensions/object_spec.rb +0 -12
- data/spec/spec/extensions/main_spec.rb +3 -8
- data/spec/spec/matchers/change_spec.rb +16 -6
- data/spec/spec/matchers/handler_spec.rb +58 -37
- data/spec/spec/matchers/has_spec.rb +10 -0
- data/spec/spec/matchers/have_spec.rb +105 -2
- data/spec/spec/matchers/operator_matcher_spec.rb +35 -2
- data/spec/spec/matchers/simple_matcher_spec.rb +64 -2
- data/spec/spec/mocks/any_number_of_times_spec.rb +7 -0
- data/spec/spec/mocks/bug_report_496.rb +17 -0
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +7 -1
- data/spec/spec/mocks/hash_including_matcher_spec.rb +45 -24
- data/spec/spec/mocks/mock_spec.rb +55 -10
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +54 -0
- data/spec/spec/mocks/null_object_mock_spec.rb +14 -0
- data/spec/spec/mocks/options_hash_spec.rb +18 -28
- data/spec/spec/mocks/partial_mock_spec.rb +2 -0
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +20 -6
- data/spec/spec/mocks/stub_spec.rb +7 -0
- data/spec/spec/runner/command_line_spec.rb +5 -12
- data/spec/spec/runner/drb_command_line_spec.rb +13 -6
- data/spec/spec/runner/formatter/html_formatter_spec.rb +2 -1
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +20 -2
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -1
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/story/html_formatter_spec.rb +76 -2
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +161 -0
- data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
- data/spec/spec/runner/heckle_runner_spec.rb +8 -8
- data/spec/spec/runner/option_parser_spec.rb +21 -6
- data/spec/spec/runner/output_one_time_fixture_runner.rb +1 -1
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -0
- data/spec/spec/runner/reporter_spec.rb +51 -5
- data/spec/spec/runner/spec_parser_spec.rb +4 -4
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +2 -5
- data/spec/spec/story/runner/story_mediator_spec.rb +10 -0
- data/spec/spec/story/runner/story_parser_spec.rb +23 -6
- data/spec/spec/story/scenario_spec.rb +1 -3
- data/spec/spec/story/step_mother_spec.rb +12 -0
- data/spec/spec/story/step_spec.rb +57 -4
- data/spec/spec/story/story_spec.rb +1 -3
- data/spec/spec/story/world_spec.rb +1 -1
- data/spec/spec_helper.rb +21 -68
- data/stories/all.rb +1 -1
- data/stories/configuration/before_blocks.story +21 -0
- data/stories/configuration/stories.rb +7 -0
- data/stories/example_groups/stories.rb +3 -4
- data/stories/resources/spec/before_blocks_example.rb +32 -0
- data/stories/stories/multiline_steps.story +23 -0
- data/stories/stories/steps/multiline_steps.rb +13 -0
- data/stories/stories/stories.rb +6 -0
- data/story_server/prototype/javascripts/builder.js +136 -0
- data/story_server/prototype/javascripts/controls.js +972 -0
- data/story_server/prototype/javascripts/dragdrop.js +976 -0
- data/story_server/prototype/javascripts/effects.js +1117 -0
- data/story_server/prototype/javascripts/prototype.js +4140 -0
- data/story_server/prototype/javascripts/rspec.js +149 -0
- data/story_server/prototype/javascripts/scriptaculous.js +58 -0
- data/story_server/prototype/javascripts/slider.js +276 -0
- data/story_server/prototype/javascripts/sound.js +55 -0
- data/story_server/prototype/javascripts/unittest.js +568 -0
- data/story_server/prototype/lib/server.rb +24 -0
- data/story_server/prototype/stories.html +176 -0
- data/story_server/prototype/stylesheets/rspec.css +136 -0
- data/story_server/prototype/stylesheets/test.css +90 -0
- metadata +166 -166
- data/README +0 -36
- data/UPGRADE +0 -7
- data/bin/spec_translator +0 -8
- data/lib/spec/mocks/argument_constraint_matchers.rb +0 -31
- data/lib/spec/translator.rb +0 -114
- data/spec/spec/example/example_spec.rb +0 -53
- data/spec/spec/runner/execution_context_spec.rb +0 -37
- data/spec/spec/translator_spec.rb +0 -265
|
@@ -48,53 +48,73 @@ end
|
|
|
48
48
|
|
|
49
49
|
module Spec
|
|
50
50
|
module Expectations
|
|
51
|
-
describe ExpectationMatcherHandler
|
|
52
|
-
|
|
53
|
-
matcher
|
|
54
|
-
|
|
55
|
-
matcher.should_receive(:matches?).with(actual).and_return(true)
|
|
56
|
-
ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "should explain when the matcher parameter is not a matcher" do
|
|
60
|
-
begin
|
|
61
|
-
nonmatcher = mock("nonmatcher")
|
|
51
|
+
describe ExpectationMatcherHandler do
|
|
52
|
+
describe "#handle_matcher" do
|
|
53
|
+
it "should ask the matcher if it matches" do
|
|
54
|
+
matcher = mock("matcher")
|
|
62
55
|
actual = Object.new
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
matcher.should_receive(:matches?).with(actual).and_return(true)
|
|
57
|
+
ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
|
65
58
|
end
|
|
59
|
+
|
|
60
|
+
it "should explain when the matcher parameter is not a matcher" do
|
|
61
|
+
begin
|
|
62
|
+
nonmatcher = mock("nonmatcher")
|
|
63
|
+
actual = Object.new
|
|
64
|
+
ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
|
|
65
|
+
rescue Spec::Expectations::InvalidMatcherError => e
|
|
66
|
+
end
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
e.message.should =~ /^Expected a matcher, got /
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should return the match value" do
|
|
72
|
+
matcher = mock("matcher")
|
|
73
|
+
actual = Object.new
|
|
74
|
+
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
|
|
75
|
+
ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
|
|
76
|
+
end
|
|
68
77
|
end
|
|
69
78
|
end
|
|
70
79
|
|
|
71
|
-
describe NegativeExpectationMatcherHandler
|
|
72
|
-
|
|
73
|
-
matcher
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
it "should ask the matcher if it matches" do
|
|
82
|
-
matcher = mock("matcher")
|
|
83
|
-
actual = Object.new
|
|
84
|
-
matcher.stub!(:negative_failure_message)
|
|
85
|
-
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
86
|
-
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
|
87
|
-
end
|
|
80
|
+
describe NegativeExpectationMatcherHandler do
|
|
81
|
+
describe "#handle_matcher" do
|
|
82
|
+
it "should explain when matcher does not support should_not" do
|
|
83
|
+
matcher = mock("matcher")
|
|
84
|
+
matcher.stub!(:matches?)
|
|
85
|
+
actual = Object.new
|
|
86
|
+
lambda {
|
|
87
|
+
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
|
88
|
+
}.should fail_with(/Matcher does not support should_not.\n/)
|
|
89
|
+
end
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
nonmatcher = mock("nonmatcher")
|
|
91
|
+
it "should ask the matcher if it matches" do
|
|
92
|
+
matcher = mock("matcher")
|
|
92
93
|
actual = Object.new
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
matcher.stub!(:negative_failure_message)
|
|
95
|
+
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
96
|
+
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should explain when the matcher parameter is not a matcher" do
|
|
100
|
+
begin
|
|
101
|
+
nonmatcher = mock("nonmatcher")
|
|
102
|
+
actual = Object.new
|
|
103
|
+
NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
|
|
104
|
+
rescue Spec::Expectations::InvalidMatcherError => e
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
e.message.should =~ /^Expected a matcher, got /
|
|
95
108
|
end
|
|
96
109
|
|
|
97
|
-
|
|
110
|
+
|
|
111
|
+
it "should return the match value" do
|
|
112
|
+
matcher = mock("matcher")
|
|
113
|
+
actual = Object.new
|
|
114
|
+
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
115
|
+
matcher.stub!(:negative_failure_message).and_return("ignore")
|
|
116
|
+
NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
|
|
117
|
+
end
|
|
98
118
|
end
|
|
99
119
|
end
|
|
100
120
|
|
|
@@ -124,6 +144,7 @@ module Spec
|
|
|
124
144
|
}.should fail_with(/Matcher does not support should_not.\n/)
|
|
125
145
|
end
|
|
126
146
|
|
|
147
|
+
|
|
127
148
|
end
|
|
128
149
|
end
|
|
129
150
|
end
|
|
@@ -51,3 +51,13 @@ describe "should_not have_sym(*args)" do
|
|
|
51
51
|
lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
describe Spec::Matchers::Has do
|
|
56
|
+
it "should work when the target implements #send" do
|
|
57
|
+
o = {:a => "A"}
|
|
58
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
|
59
|
+
lambda {
|
|
60
|
+
o.should have_key(:a)
|
|
61
|
+
}.should_not raise_error
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -47,11 +47,40 @@ describe "should have(n).items" do
|
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
|
51
|
+
include HaveSpecHelper
|
|
52
|
+
|
|
53
|
+
before(:each) do
|
|
54
|
+
unless defined?(ActiveSupport::Inflector)
|
|
55
|
+
@active_support_was_not_defined
|
|
56
|
+
module ActiveSupport
|
|
57
|
+
class Inflector
|
|
58
|
+
def self.pluralize(string)
|
|
59
|
+
string.to_s + 's'
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'should pluralize the collection name' do
|
|
67
|
+
owner = create_collection_owner_with(1)
|
|
68
|
+
owner.should have(1).item
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
after(:each) do
|
|
72
|
+
if @active_support_was_not_defined
|
|
73
|
+
Object.send :remove_const, :ActiveSupport
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
50
78
|
describe 'should have(1).item when Inflector is defined' do
|
|
51
79
|
include HaveSpecHelper
|
|
52
80
|
|
|
53
|
-
before do
|
|
54
|
-
unless
|
|
81
|
+
before(:each) do
|
|
82
|
+
unless defined?(Inflector)
|
|
83
|
+
@inflector_was_not_defined
|
|
55
84
|
class Inflector
|
|
56
85
|
def self.pluralize(string)
|
|
57
86
|
string.to_s + 's'
|
|
@@ -64,6 +93,12 @@ describe 'should have(1).item when Inflector is defined' do
|
|
|
64
93
|
owner = create_collection_owner_with(1)
|
|
65
94
|
owner.should have(1).item
|
|
66
95
|
end
|
|
96
|
+
|
|
97
|
+
after(:each) do
|
|
98
|
+
if @inflector_was_not_defined
|
|
99
|
+
Object.send :remove_const, :Inflector
|
|
100
|
+
end
|
|
101
|
+
end
|
|
67
102
|
end
|
|
68
103
|
|
|
69
104
|
describe "should have(n).items where result responds to items but returns something other than a collection" do
|
|
@@ -289,3 +324,71 @@ describe "have(n).things on an object which is not a collection nor contains one
|
|
|
289
324
|
lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
|
|
290
325
|
end
|
|
291
326
|
end
|
|
327
|
+
|
|
328
|
+
describe Spec::Matchers::Have, "for a collection owner that implements #send" do
|
|
329
|
+
include HaveSpecHelper
|
|
330
|
+
|
|
331
|
+
before(:each) do
|
|
332
|
+
@collection = Object.new
|
|
333
|
+
def @collection.floozles; [1,2] end
|
|
334
|
+
def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
it "should work in the straightforward case" do
|
|
338
|
+
lambda {
|
|
339
|
+
@collection.should have(2).floozles
|
|
340
|
+
}.should_not raise_error
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it "should work when doing automatic pluralization" do
|
|
344
|
+
lambda {
|
|
345
|
+
@collection.should have_at_least(1).floozle
|
|
346
|
+
}.should_not raise_error
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
it "should blow up when the owner doesn't respond to that method" do
|
|
350
|
+
lambda {
|
|
351
|
+
@collection.should have(99).problems
|
|
352
|
+
}.should raise_error(NoMethodError, /problems/)
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
module Spec
|
|
357
|
+
module Matchers
|
|
358
|
+
describe Have do
|
|
359
|
+
it "should have method_missing as private" do
|
|
360
|
+
Have.private_instance_methods.should include("method_missing")
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
describe "respond_to?" do
|
|
364
|
+
before :each do
|
|
365
|
+
@have = Have.new(:foo)
|
|
366
|
+
@a_method_which_have_defines = Have.instance_methods.first
|
|
367
|
+
@a_method_which_object_defines = Object.instance_methods.first
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
it "should be true for a method which Have defines" do
|
|
371
|
+
@have.should respond_to(@a_method_which_have_defines)
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
it "should be true for a method that it's superclass (Object) defines" do
|
|
375
|
+
@have.should respond_to(@a_method_which_object_defines)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
it "should be false for a method which neither Object nor nor Have defines" do
|
|
379
|
+
@have.should_not respond_to(:foo_bar_baz)
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
it "should be false if the owner doesn't respond to the method" do
|
|
383
|
+
have = Have.new(99)
|
|
384
|
+
have.should_not respond_to(:problems)
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
it "should be true if the owner responds to the method" do
|
|
388
|
+
have = Have.new(:a_symbol)
|
|
389
|
+
have.should respond_to(:to_sym)
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
end
|
|
@@ -10,12 +10,17 @@ describe "should ==" do
|
|
|
10
10
|
subject.should == "apple"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
it "should return true on success" do
|
|
14
|
+
subject = "apple"
|
|
15
|
+
(subject.should == "apple").should be_true
|
|
16
|
+
end
|
|
17
|
+
|
|
13
18
|
it "should fail when target.==(actual) returns false" do
|
|
14
19
|
subject = "apple"
|
|
15
20
|
Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n got: "apple" (using ==)], "orange", "apple")
|
|
16
21
|
subject.should == "orange"
|
|
17
22
|
end
|
|
18
|
-
|
|
23
|
+
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
describe "should_not ==" do
|
|
@@ -26,12 +31,17 @@ describe "should_not ==" do
|
|
|
26
31
|
subject.should_not == "apple"
|
|
27
32
|
end
|
|
28
33
|
|
|
34
|
+
it "should return true on success" do
|
|
35
|
+
subject = "apple"
|
|
36
|
+
(subject.should_not == "orange").should be_true
|
|
37
|
+
end
|
|
38
|
+
|
|
29
39
|
it "should fail when target.==(actual) returns false" do
|
|
30
40
|
subject = "apple"
|
|
31
41
|
Spec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple",\n got: "apple"], "apple", "apple")
|
|
32
42
|
subject.should_not == "apple"
|
|
33
43
|
end
|
|
34
|
-
|
|
44
|
+
|
|
35
45
|
end
|
|
36
46
|
|
|
37
47
|
describe "should ===" do
|
|
@@ -156,3 +166,26 @@ describe "should <=" do
|
|
|
156
166
|
|
|
157
167
|
end
|
|
158
168
|
|
|
169
|
+
describe Spec::Matchers::PositiveOperatorMatcher do
|
|
170
|
+
|
|
171
|
+
it "should work when the target has implemented #send" do
|
|
172
|
+
o = Object.new
|
|
173
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
|
174
|
+
lambda {
|
|
175
|
+
o.should == o
|
|
176
|
+
}.should_not raise_error
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe Spec::Matchers::NegativeOperatorMatcher do
|
|
182
|
+
|
|
183
|
+
it "should work when the target has implemented #send" do
|
|
184
|
+
o = Object.new
|
|
185
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
|
186
|
+
lambda {
|
|
187
|
+
o.should_not == :foo
|
|
188
|
+
}.should_not raise_error
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
end
|
|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
|
3
3
|
module Spec
|
|
4
4
|
module Matchers
|
|
5
5
|
describe SimpleMatcher do
|
|
6
|
-
it "should
|
|
6
|
+
it "should pass match arg to block" do
|
|
7
7
|
actual = nil
|
|
8
8
|
matcher = simple_matcher("message") do |given| actual = given end
|
|
9
9
|
matcher.matches?("foo")
|
|
@@ -22,10 +22,72 @@ module Spec
|
|
|
22
22
|
matcher.negative_failure_message.should =~ /expected not to get \"thing\", but got \"other\"/
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
it "should provide
|
|
25
|
+
it "should provide the given description" do
|
|
26
26
|
matcher = simple_matcher("thing") do end
|
|
27
27
|
matcher.description.should =="thing"
|
|
28
28
|
end
|
|
29
|
+
|
|
30
|
+
it "should fail if a wrapped 'should' fails" do
|
|
31
|
+
matcher = simple_matcher("should fail") do
|
|
32
|
+
2.should == 3
|
|
33
|
+
end
|
|
34
|
+
lambda do
|
|
35
|
+
matcher.matches?("anything").should be_true
|
|
36
|
+
end.should fail_with(/expected: 3/)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "with arity of 2" do
|
|
41
|
+
it "should provide the matcher so you can access its messages" do
|
|
42
|
+
provided_matcher = nil
|
|
43
|
+
matcher = simple_matcher("thing") do |given, matcher|
|
|
44
|
+
provided_matcher = matcher
|
|
45
|
+
end
|
|
46
|
+
matcher.matches?("anything")
|
|
47
|
+
provided_matcher.should equal(matcher)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should support a custom failure message" do
|
|
51
|
+
matcher = simple_matcher("thing") do |given, matcher|
|
|
52
|
+
matcher.failure_message = "custom message"
|
|
53
|
+
end
|
|
54
|
+
matcher.matches?("other")
|
|
55
|
+
matcher.failure_message.should == "custom message"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should complain when asked for a failure message if you don't give it a description or a message" do
|
|
59
|
+
matcher = simple_matcher do |given, matcher| end
|
|
60
|
+
matcher.matches?("other")
|
|
61
|
+
matcher.failure_message.should =~ /No description provided/
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should support a custom negative failure message" do
|
|
65
|
+
matcher = simple_matcher("thing") do |given, matcher|
|
|
66
|
+
matcher.negative_failure_message = "custom message"
|
|
67
|
+
end
|
|
68
|
+
matcher.matches?("other")
|
|
69
|
+
matcher.negative_failure_message.should == "custom message"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should complain when asked for a negative failure message if you don't give it a description or a message" do
|
|
73
|
+
matcher = simple_matcher do |given, matcher| end
|
|
74
|
+
matcher.matches?("other")
|
|
75
|
+
matcher.negative_failure_message.should =~ /No description provided/
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should support a custom description" do
|
|
79
|
+
matcher = simple_matcher("thing") do |given, matcher|
|
|
80
|
+
matcher.description = "custom message"
|
|
81
|
+
end
|
|
82
|
+
matcher.matches?("description")
|
|
83
|
+
matcher.description.should == "custom message"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should tell you no description was provided when it doesn't receive one" do
|
|
87
|
+
matcher = simple_matcher do end
|
|
88
|
+
matcher.description.should =~ /No description provided/
|
|
89
|
+
end
|
|
29
90
|
end
|
|
91
|
+
|
|
30
92
|
end
|
|
31
93
|
end
|
|
@@ -23,6 +23,13 @@ module Spec
|
|
|
23
23
|
it "should pass if any number of times method is not called" do
|
|
24
24
|
@mock.should_receive(:random_call).any_number_of_times
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
it "should return the mocked value when called after a similar stub" do
|
|
28
|
+
@mock.stub!(:message).and_return :stub_value
|
|
29
|
+
@mock.should_receive(:message).any_number_of_times.and_return(:mock_value)
|
|
30
|
+
@mock.message.should == :mock_value
|
|
31
|
+
@mock.message.should == :mock_value
|
|
32
|
+
end
|
|
26
33
|
end
|
|
27
34
|
|
|
28
35
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
class BaseClass
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class SubClass < BaseClass
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "a message expectation on a base class object" do
|
|
10
|
+
it "should correctly pick up message sent to it subclass" do
|
|
11
|
+
pending("fix for http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/496") do
|
|
12
|
+
BaseClass.should_receive(:new).once
|
|
13
|
+
SubClass.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
@@ -82,6 +82,13 @@ module Spec
|
|
|
82
82
|
@mock.msg({})
|
|
83
83
|
end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (hash_including(:a=>1)) but received it with ({})")
|
|
84
84
|
end
|
|
85
|
+
|
|
86
|
+
it "should fail with block constraints" do
|
|
87
|
+
lambda do
|
|
88
|
+
@mock.should_receive(:msg).with {|arg| arg.should == :received }
|
|
89
|
+
@mock.msg :no_msg_for_you
|
|
90
|
+
end.should raise_error(Spec::Expectations::ExpectationNotMetError, /expected: :received.*\s*.*got: :no_msg_for_you/)
|
|
91
|
+
end
|
|
85
92
|
|
|
86
93
|
end
|
|
87
94
|
|
|
@@ -116,7 +123,6 @@ module Spec
|
|
|
116
123
|
@mock.random_call(123)
|
|
117
124
|
end.should raise_error(MockExpectationError)
|
|
118
125
|
end
|
|
119
|
-
|
|
120
126
|
|
|
121
127
|
end
|
|
122
128
|
end
|