dchelimsky-rspec 1.1.12 → 1.1.99.1

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.
Files changed (147) hide show
  1. data/History.txt +35 -0
  2. data/License.txt +1 -1
  3. data/Manifest.txt +22 -73
  4. data/README.txt +2 -2
  5. data/Rakefile +32 -7
  6. data/TODO.txt +9 -4
  7. data/bin/spec +1 -1
  8. data/cucumber.yml +2 -0
  9. data/examples/failing/spec_helper.rb +1 -1
  10. data/examples/passing/filtered_formatter.rb +18 -0
  11. data/examples/passing/filtered_formatter_example.rb +31 -0
  12. data/examples/passing/spec_helper.rb +1 -1
  13. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
  14. data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
  15. data/features/example_groups/autogenerated_docstrings.feature +2 -2
  16. data/features/example_groups/example_group_with_should_methods.feature +1 -1
  17. data/features/example_groups/nested_groups.feature +1 -1
  18. data/features/interop/examples_and_tests_together.feature +1 -1
  19. data/features/interop/test_but_not_test_unit.feature +1 -1
  20. data/features/interop/test_case_with_should_methods.feature +1 -1
  21. data/features/mock_framework_integration/use_flexmock.feature +22 -4
  22. data/features/mock_framework_integration/use_mocha.feature +27 -0
  23. data/features/mock_framework_integration/use_rr.feature +27 -0
  24. data/features/step_definitions/running_rspec.rb +5 -3
  25. data/features/support/env.rb +1 -1
  26. data/features-pending/cli/conditional_exclusion.feature +39 -0
  27. data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +1 -0
  28. data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +1 -0
  29. data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +1 -0
  30. data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
  31. data/lib/spec/autorun.rb +3 -0
  32. data/lib/spec/example/before_and_after_hooks.rb +5 -20
  33. data/lib/spec/example/example_description.rb +15 -0
  34. data/lib/spec/example/example_group.rb +0 -15
  35. data/lib/spec/example/example_group_factory.rb +34 -46
  36. data/lib/spec/example/example_group_hierarchy.rb +53 -0
  37. data/lib/spec/example/example_group_methods.rb +96 -211
  38. data/lib/spec/example/example_methods.rb +62 -81
  39. data/lib/spec/example/module_reopening_fix.rb +23 -1
  40. data/lib/spec/example/predicate_matchers.rb +47 -0
  41. data/lib/spec/example/subject.rb +91 -0
  42. data/lib/spec/example.rb +4 -0
  43. data/lib/spec/expectations/extensions.rb +0 -1
  44. data/lib/spec/expectations/handler.rb +6 -1
  45. data/lib/spec/expectations.rb +1 -1
  46. data/lib/spec/interop/test/unit/testcase.rb +5 -22
  47. data/lib/spec/interop/test.rb +1 -0
  48. data/lib/spec/matchers/be.rb +2 -7
  49. data/lib/spec/matchers/be_close.rb +20 -5
  50. data/lib/spec/matchers/change.rb +5 -3
  51. data/lib/spec/matchers/eql.rb +24 -6
  52. data/lib/spec/matchers/equal.rb +24 -6
  53. data/lib/spec/matchers/exist.rb +21 -5
  54. data/lib/spec/matchers/generated_descriptions.rb +2 -2
  55. data/lib/spec/matchers/has.rb +28 -11
  56. data/lib/spec/matchers/match.rb +25 -7
  57. data/lib/spec/matchers/match_array.rb +1 -1
  58. data/lib/spec/matchers/method_missing.rb +2 -2
  59. data/lib/spec/matchers/operator_matcher.rb +12 -5
  60. data/lib/spec/matchers/raise_error.rb +1 -1
  61. data/lib/spec/matchers/respond_to.rb +1 -1
  62. data/lib/spec/matchers/satisfy.rb +5 -5
  63. data/lib/spec/matchers/throw_symbol.rb +1 -3
  64. data/lib/spec/mocks/argument_expectation.rb +1 -1
  65. data/lib/spec/mocks/argument_matchers.rb +233 -0
  66. data/lib/spec/mocks/error_generator.rb +2 -6
  67. data/lib/spec/mocks/message_expectation.rb +3 -11
  68. data/lib/spec/mocks/mock.rb +1 -1
  69. data/lib/spec/mocks/proxy.rb +5 -1
  70. data/lib/spec/runner/configuration.rb +3 -3
  71. data/lib/spec/runner/drb_command_line.rb +2 -1
  72. data/lib/spec/runner/example_group_runner.rb +2 -1
  73. data/lib/spec/runner/formatter/base_text_formatter.rb +28 -17
  74. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
  75. data/lib/spec/runner/formatter/html_formatter.rb +2 -3
  76. data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
  77. data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
  78. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
  79. data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
  80. data/lib/spec/runner/option_parser.rb +16 -19
  81. data/lib/spec/runner/options.rb +28 -26
  82. data/lib/spec/runner/reporter.rb +8 -9
  83. data/lib/spec/runner.rb +6 -28
  84. data/lib/spec/test/unit.rb +10 -0
  85. data/lib/spec/version.rb +2 -2
  86. data/{features/support → resources}/helpers/cmdline.rb +2 -2
  87. data/resources/rake/verify_rcov.rake +1 -1
  88. data/resources/spec/example_group_with_should_methods.rb +1 -1
  89. data/resources/spec/simple_spec.rb +1 -1
  90. data/resources/test/spec_and_test_together.rb +2 -3
  91. data/resources/test/spec_including_test_but_not_unit.rb +1 -1
  92. data/resources/test/test_case_with_should_methods.rb +2 -3
  93. data/rspec.gemspec +5 -5
  94. data/spec/spec/dsl/main_spec.rb +3 -3
  95. data/spec/spec/example/example_group_class_definition_spec.rb +11 -14
  96. data/spec/spec/example/example_group_factory_spec.rb +31 -44
  97. data/spec/spec/example/example_group_methods_spec.rb +86 -52
  98. data/spec/spec/example/example_group_spec.rb +16 -75
  99. data/spec/spec/example/example_matcher_spec.rb +10 -10
  100. data/spec/spec/example/example_methods_spec.rb +101 -241
  101. data/spec/spec/example/nested_example_group_spec.rb +2 -2
  102. data/spec/spec/example/pending_module_spec.rb +1 -1
  103. data/spec/spec/example/shared_example_group_spec.rb +2 -2
  104. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
  105. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
  106. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
  107. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
  108. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
  109. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
  110. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
  111. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
  112. data/spec/spec/matchers/change_spec.rb +8 -0
  113. data/spec/spec/matchers/exist_spec.rb +8 -4
  114. data/spec/spec/matchers/handler_spec.rb +8 -1
  115. data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
  116. data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
  117. data/spec/spec/mocks/failing_argument_matchers_spec.rb +95 -0
  118. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  119. data/spec/spec/mocks/passing_argument_matchers_spec.rb +145 -0
  120. data/spec/spec/runner/configuration_spec.rb +12 -12
  121. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +72 -1
  122. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
  123. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
  124. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
  125. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
  126. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
  127. data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
  128. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
  129. data/spec/spec/runner/formatter/profile_formatter_spec.rb +1 -1
  130. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +8 -6
  131. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
  132. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
  133. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
  134. data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +10 -8
  135. data/spec/spec/runner/heckle_runner_spec.rb +1 -1
  136. data/spec/spec/runner/option_parser_spec.rb +15 -13
  137. data/spec/spec/runner/options_spec.rb +34 -0
  138. data/spec/spec/runner/reporter_spec.rb +65 -61
  139. data/spec/spec/runner/spec_drb.opts +1 -0
  140. data/spec/spec/runner_spec.rb +7 -5
  141. data/spec/spec_helper.rb +23 -0
  142. metadata +25 -76
  143. data/examples/passing/legacy_spec.rb +0 -11
  144. data/features/support/helpers/story_helper.rb +0 -13
  145. data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
  146. data/resources/spec/spec_with_flexmock.rb +0 -19
  147. data/spec/spec/spec_spec.rb +0 -21
@@ -8,7 +8,7 @@ module Spec
8
8
  before(:each) do
9
9
  @formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
10
10
  options.formatters << formatter
11
- @example_group = Class.new(ExampleGroup).describe("example_group")
11
+ @example_group = Class.new(ExampleGroupDouble).describe("example_group")
12
12
  class << example_group
13
13
  public :include
14
14
  end
@@ -22,7 +22,7 @@ module Spec
22
22
 
23
23
  describe "#register" do
24
24
  it "creates a new shared example group with the submitted args" do
25
- block = lambda {}
25
+ block = lambda {|a|}
26
26
  group = SharedExampleGroup.new("shared group") do end
27
27
  Spec::Example::SharedExampleGroup.should_receive(:new).with("share me", &block).and_return(group)
28
28
  Spec::Example::SharedExampleGroup.register("share me", &block)
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  describe "example group with failures" do
7
7
  it "should fail" do
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  describe "example group with passing examples" do
7
7
  it "should pass" do
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  describe "example group with errors" do
7
7
  it "should raise errors" do
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  describe "options hash" do
7
7
  describe "#options" do
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  class TestCaseThatFails < Test::Unit::TestCase
7
7
  def test_that_fails
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  class TestCaseThatPasses < Test::Unit::TestCase
7
7
  def test_that_passes
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require 'test/unit'
4
- require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  class TestCaseWithErrors < Test::Unit::TestCase
7
7
  def test_with_error
@@ -1,7 +1,7 @@
1
1
  rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
2
  $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
- require "test/unit"
4
- require "spec"
3
+ require 'spec/autorun'
4
+ require 'spec/test/unit'
5
5
 
6
6
  module Test
7
7
  module Unit
@@ -20,6 +20,10 @@ describe "should change(actual, message)" do
20
20
  lambda {}.should change(@instance, :some_value)
21
21
  end.should fail_with("some_value should have changed, but is still 5")
22
22
  end
23
+
24
+ it "provides a #description" do
25
+ change(@instance, :some_value).description.should == "change #some_value"
26
+ end
23
27
  end
24
28
 
25
29
  describe "should_not change(actual, message)" do
@@ -60,6 +64,10 @@ describe "should change { block }" do
60
64
  lambda {}.should change do; end
61
65
  end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
62
66
  end
67
+
68
+ it "provides a #description" do
69
+ change { @instance.some_value }.description.should == "change #result"
70
+ end
63
71
  end
64
72
 
65
73
  describe "should_not change { block }" do
@@ -23,7 +23,7 @@ class SubstanceTester
23
23
  end
24
24
  end
25
25
 
26
- describe "should exist," do
26
+ describe "should exist" do
27
27
 
28
28
  before(:each) do
29
29
  @real = Substance.new true, 'something real'
@@ -32,15 +32,19 @@ describe "should exist," do
32
32
 
33
33
  describe "within an example group" do
34
34
 
35
- it "should pass if target exists" do
35
+ it "passes if target exists" do
36
36
  @real.should exist
37
37
  end
38
38
 
39
- it "should fail if target does not exist" do
39
+ it "fails if target does not exist" do
40
40
  lambda { @imaginary.should exist }.should fail
41
41
  end
42
42
 
43
- it "should pass if target doesn't exist" do
43
+ it "describes itself" do
44
+ exist.description.should == "exists"
45
+ end
46
+
47
+ it "passes should_not exist if target doesn't exist" do
44
48
  lambda { @real.should_not exist }.should fail
45
49
  end
46
50
  end
@@ -68,7 +68,14 @@ module Spec
68
68
 
69
69
  describe NegativeExpectationMatcherHandler do
70
70
  describe "#handle_matcher" do
71
- it "should ask the matcher if it matches" do
71
+ it "should ask the matcher if it doesn't match when the matcher responds to #does_not_match?" do
72
+ matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil)
73
+ actual = Object.new
74
+ matcher.should_receive(:does_not_match?).with(actual).and_return(true)
75
+ Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
76
+ end
77
+
78
+ it "should ask the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
72
79
  matcher = mock("matcher")
73
80
  actual = Object.new
74
81
  matcher.stub!(:negative_failure_message)
@@ -58,7 +58,7 @@ This module should provide the following methods, each of which returns a Matche
58
58
  end
59
59
 
60
60
  it "should convert have_xyz to Has(:have_xyz)" do
61
- self.should_receive(:has).with(:have_whatever)
61
+ Has.should_receive(:new).with(:have_whatever)
62
62
  have_whatever
63
63
  end
64
64
  end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Mocks
5
+ describe "failing MockArgumentMatchers" do
6
+ before(:each) do
7
+ @mock = mock("test mock")
8
+ @reporter = Mock.new("reporter", :null_object => true)
9
+ end
10
+
11
+ after(:each) do
12
+ @mock.rspec_reset
13
+ end
14
+
15
+ it "should reject non boolean" do
16
+ @mock.should_receive(:random_call).with(boolean())
17
+ lambda do
18
+ @mock.random_call("false")
19
+ end.should raise_error(MockExpectationError)
20
+ end
21
+
22
+ it "should reject non numeric" do
23
+ @mock.should_receive(:random_call).with(an_instance_of(Numeric))
24
+ lambda do
25
+ @mock.random_call("1")
26
+ end.should raise_error(MockExpectationError)
27
+ end
28
+
29
+ it "should reject non string" do
30
+ @mock.should_receive(:random_call).with(an_instance_of(String))
31
+ lambda do
32
+ @mock.random_call(123)
33
+ end.should raise_error(MockExpectationError)
34
+ end
35
+
36
+ it "should reject goose when expecting a duck" do
37
+ @mock.should_receive(:random_call).with(duck_type(:abs, :div))
38
+ lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(MockExpectationError)
39
+ end
40
+
41
+ it "should fail if regexp does not match submitted string" do
42
+ @mock.should_receive(:random_call).with(/bcd/)
43
+ lambda { @mock.random_call("abc") }.should raise_error(MockExpectationError)
44
+ end
45
+
46
+ it "should fail if regexp does not match submitted regexp" do
47
+ @mock.should_receive(:random_call).with(/bcd/)
48
+ lambda { @mock.random_call(/bcde/) }.should raise_error(MockExpectationError)
49
+ end
50
+
51
+ it "should fail for a hash w/ wrong values" do
52
+ @mock.should_receive(:random_call).with(:a => "b", :c => "d")
53
+ lambda do
54
+ @mock.random_call(:a => "b", :c => "e")
55
+ end.should raise_error(MockExpectationError, /Mock 'test mock' expected :random_call with \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\) but received it with \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
56
+ end
57
+
58
+ it "should fail for a hash w/ wrong keys" do
59
+ @mock.should_receive(:random_call).with(:a => "b", :c => "d")
60
+ lambda do
61
+ @mock.random_call("a" => "b", "c" => "d")
62
+ end.should raise_error(MockExpectationError, /Mock 'test mock' expected :random_call with \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\) but received it with \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
63
+ end
64
+
65
+ it "should match against a Matcher" do
66
+ lambda do
67
+ @mock.should_receive(:msg).with(equal(3))
68
+ @mock.msg(37)
69
+ end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (equal 3) but received it with (37)")
70
+ end
71
+
72
+ it "should fail no_args with one arg" do
73
+ lambda do
74
+ @mock.should_receive(:msg).with(no_args)
75
+ @mock.msg(37)
76
+ end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (no args) but received it with (37)")
77
+ end
78
+
79
+ it "should fail hash_including with missing key" do
80
+ lambda do
81
+ @mock.should_receive(:msg).with(hash_including(:a => 1))
82
+ @mock.msg({})
83
+ end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (hash_including(:a=>1)) but received it with ({})")
84
+ end
85
+
86
+ it "should fail with block matchers" 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
92
+
93
+ end
94
+ end
95
+ end
@@ -33,7 +33,7 @@ module Spec
33
33
  describe "#allow_message_expectations_on_nil" do
34
34
 
35
35
  it "should not effect subsequent examples" do
36
- example_group = Class.new(ExampleGroup)
36
+ example_group = Class.new(::Spec::Example::ExampleGroupDouble)
37
37
  example_group.it("when called in one example that doesn't end up setting an expectation on nil") do
38
38
  allow_message_expectations_on_nil
39
39
  end
@@ -0,0 +1,145 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Mocks
5
+ describe "mock argument matchers", :shared => true do
6
+ before(:each) do
7
+ @mock = Mock.new("test mock")
8
+ Kernel.stub!(:warn)
9
+ end
10
+
11
+ after(:each) do
12
+ @mock.rspec_verify
13
+ end
14
+ end
15
+
16
+ describe Methods, "handling argument matchers" do
17
+ it_should_behave_like "mock argument matchers"
18
+
19
+ it "should accept true as boolean()" do
20
+ @mock.should_receive(:random_call).with(boolean())
21
+ @mock.random_call(true)
22
+ end
23
+
24
+ it "should accept false as boolean()" do
25
+ @mock.should_receive(:random_call).with(boolean())
26
+ @mock.random_call(false)
27
+ end
28
+
29
+ it "should accept fixnum as kind_of(Numeric)" do
30
+ @mock.should_receive(:random_call).with(kind_of(Numeric))
31
+ @mock.random_call(1)
32
+ end
33
+
34
+ it "should accept float as an_instance_of(Numeric)" do
35
+ @mock.should_receive(:random_call).with(kind_of(Numeric))
36
+ @mock.random_call(1.5)
37
+ end
38
+
39
+ it "accepts fixnum as instance_of(Fixnum)" do
40
+ @mock.should_receive(:random_call).with(instance_of(Fixnum))
41
+ @mock.random_call(1)
42
+ end
43
+
44
+ it "should NOT accept fixnum as instance_of(Numeric)" do
45
+ @mock.should_not_receive(:random_call).with(instance_of(Numeric))
46
+ @mock.random_call(1)
47
+ end
48
+
49
+ it "should NOT accept float as instance_of(Numeric)" do
50
+ @mock.should_not_receive(:random_call).with(instance_of(Numeric))
51
+ @mock.random_call(1.5)
52
+ end
53
+
54
+ it "should accept string as anything()" do
55
+ @mock.should_receive(:random_call).with("a", anything(), "c")
56
+ @mock.random_call("a", "whatever", "c")
57
+ end
58
+
59
+ it "should match duck type with one method" do
60
+ @mock.should_receive(:random_call).with(duck_type(:length))
61
+ @mock.random_call([])
62
+ end
63
+
64
+ it "should match duck type with two methods" do
65
+ @mock.should_receive(:random_call).with(duck_type(:abs, :div))
66
+ @mock.random_call(1)
67
+ end
68
+
69
+ it "should match no args against any_args()" do
70
+ @mock.should_receive(:random_call).with(any_args)
71
+ @mock.random_call()
72
+ end
73
+
74
+ it "should match one arg against any_args()" do
75
+ @mock.should_receive(:random_call).with(any_args)
76
+ @mock.random_call("a string")
77
+ end
78
+
79
+ it "should match no args against no_args()" do
80
+ @mock.should_receive(:random_call).with(no_args)
81
+ @mock.random_call()
82
+ end
83
+
84
+ it "should match hash with hash_including same hash" do
85
+ @mock.should_receive(:random_call).with(hash_including(:a => 1))
86
+ @mock.random_call(:a => 1)
87
+ end
88
+
89
+ end
90
+
91
+ describe Methods, "handling block matchers" do
92
+ it_should_behave_like "mock argument matchers"
93
+
94
+ it "should match arguments against RSpec expectations" do
95
+ @mock.should_receive(:random_call).with {|arg1, arg2, arr, *rest|
96
+ arg1.should == 5
97
+ arg2.should have_at_least(3).characters
98
+ arg2.should have_at_most(10).characters
99
+ arr.map {|i| i * 2}.should == [2,4,6]
100
+ rest.should == [:fee, "fi", 4]
101
+ }
102
+ @mock.random_call 5, "hello", [1,2,3], :fee, "fi", 4
103
+ end
104
+ end
105
+
106
+ describe Methods, "handling non-matcher arguments" do
107
+
108
+ before(:each) do
109
+ @mock = Mock.new("test mock")
110
+ end
111
+
112
+ it "should match non special symbol (can be removed when deprecated symbols are removed)" do
113
+ @mock.should_receive(:random_call).with(:some_symbol)
114
+ @mock.random_call(:some_symbol)
115
+ end
116
+
117
+ it "should match string against regexp" do
118
+ @mock.should_receive(:random_call).with(/bcd/)
119
+ @mock.random_call("abcde")
120
+ end
121
+
122
+ it "should match regexp against regexp" do
123
+ @mock.should_receive(:random_call).with(/bcd/)
124
+ @mock.random_call(/bcd/)
125
+ end
126
+
127
+ it "should match against a hash submitted and received by value" do
128
+ @mock.should_receive(:random_call).with(:a => "a", :b => "b")
129
+ @mock.random_call(:a => "a", :b => "b")
130
+ end
131
+
132
+ it "should match against a hash submitted by reference and received by value" do
133
+ opts = {:a => "a", :b => "b"}
134
+ @mock.should_receive(:random_call).with(opts)
135
+ @mock.random_call(:a => "a", :b => "b")
136
+ end
137
+
138
+ it "should match against a hash submitted by value and received by reference" do
139
+ opts = {:a => "a", :b => "b"}
140
+ @mock.should_receive(:random_call).with(:a => "a", :b => "b")
141
+ @mock.random_call(opts)
142
+ end
143
+ end
144
+ end
145
+ end
@@ -7,27 +7,27 @@ module Spec
7
7
  with_sandboxed_config do
8
8
  describe "#mock_with" do
9
9
  it "should default mock framework to rspec" do
10
- config.mock_framework.should =~ /\/adapters\/mock_frameworks\/rspec$/
10
+ config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/rspec$/
11
11
  end
12
12
 
13
13
  it "should set rspec mocking explicitly" do
14
14
  config.mock_with(:rspec)
15
- config.mock_framework.should =~ /\/adapters\/mock_frameworks\/rspec$/
15
+ config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/rspec$/
16
16
  end
17
17
 
18
18
  it "should set mocha" do
19
19
  config.mock_with(:mocha)
20
- config.mock_framework.should =~ /\/adapters\/mock_frameworks\/mocha$/
20
+ config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/mocha$/
21
21
  end
22
22
 
23
23
  it "should set flexmock" do
24
24
  config.mock_with(:flexmock)
25
- config.mock_framework.should =~ /\/adapters\/mock_frameworks\/flexmock$/
25
+ config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/flexmock$/
26
26
  end
27
27
 
28
28
  it "should set rr" do
29
29
  config.mock_with(:rr)
30
- config.mock_framework.should =~ /\/adapters\/mock_frameworks\/rr$/
30
+ config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/rr$/
31
31
  end
32
32
 
33
33
  it "should set an arbitrary adapter module" do
@@ -40,7 +40,7 @@ module Spec
40
40
  describe "#include" do
41
41
 
42
42
  before(:each) do
43
- @example_group_class = Class.new(ExampleGroup) {}
43
+ @example_group_class = Class.new(::Spec::Example::ExampleGroupDouble) {}
44
44
  Spec::Example::ExampleGroupFactory.register(:foobar, @example_group_class)
45
45
  end
46
46
 
@@ -58,7 +58,7 @@ module Spec
58
58
 
59
59
  it "should not include modules in a type they are not intended for" do
60
60
  mod = Module.new
61
- @other_example_group_class = Class.new(ExampleGroup)
61
+ @other_example_group_class = Class.new(::Spec::Example::ExampleGroupDouble)
62
62
  Spec::Example::ExampleGroupFactory.register(:baz, @other_example_group_class)
63
63
 
64
64
  config.include mod, :type => :foobar
@@ -68,7 +68,7 @@ module Spec
68
68
 
69
69
  it "accepts an Array of types" do
70
70
  mod = Module.new
71
- @other_example_group_class = Class.new(ExampleGroup)
71
+ @other_example_group_class = Class.new(::Spec::Example::ExampleGroupDouble)
72
72
  Spec::Example::ExampleGroupFactory.register(:baz, @other_example_group_class)
73
73
 
74
74
  config.include mod, :type => [:foobar, :baz]
@@ -82,7 +82,7 @@ module Spec
82
82
  describe "#extend" do
83
83
 
84
84
  before(:each) do
85
- @example_group_class = Class.new(ExampleGroup) {}
85
+ @example_group_class = Class.new(::Spec::Example::ExampleGroupDouble) {}
86
86
  Spec::Example::ExampleGroupFactory.register(:foobar, @example_group_class)
87
87
  end
88
88
 
@@ -99,7 +99,7 @@ module Spec
99
99
  end
100
100
 
101
101
  it "should not extend non-specified groups" do
102
- @other_example_group_class = Class.new(ExampleGroup)
102
+ @other_example_group_class = Class.new(::Spec::Example::ExampleGroupDouble)
103
103
  Spec::Example::ExampleGroupFactory.register(:baz, @other_example_group_class)
104
104
 
105
105
  mod = Module.new
@@ -114,9 +114,9 @@ module Spec
114
114
  describe "ordering methods: " do
115
115
 
116
116
  before(:each) do
117
- @special_example_group = Class.new(ExampleGroup).describe("special_example_group")
117
+ @special_example_group = Class.new(::Spec::Example::ExampleGroupDouble).describe("special_example_group")
118
118
  @special_child_example_group = Class.new(@special_example_group).describe("special_child_example_group")
119
- @nonspecial_example_group = Class.new(ExampleGroup).describe("nonspecial_example_group")
119
+ @nonspecial_example_group = Class.new(::Spec::Example::ExampleGroupDouble).describe("nonspecial_example_group")
120
120
  Spec::Example::ExampleGroupFactory.register(:special, @special_example_group)
121
121
  Spec::Example::ExampleGroupFactory.register(:special_child, @special_child_example_group)
122
122
  Spec::Example::ExampleGroupFactory.register(:non_special, @nonspecial_example_group)
@@ -1,6 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
  require 'spec/runner/formatter/base_text_formatter'
3
- require 'fileutils'
4
3
 
5
4
  module Spec
6
5
  module Runner
@@ -16,7 +15,79 @@ module Spec
16
15
  File.stub!(:open)
17
16
  BaseTextFormatter.new({},"#{@sandbox}/temp.rb")
18
17
  end
18
+
19
+ context "(deprecations)" do
20
+ before(:each) do
21
+ Kernel.stub!(:warn)
22
+ @io = StringIO.new
23
+ @options = mock('options')
24
+ @options.stub!(:dry_run).and_return(false)
25
+ @options.stub!(:colour).and_return(false)
26
+ @formatter = Class.new(BaseTextFormatter) do
27
+ def method_that_class_magenta(message)
28
+ magenta(message)
29
+ end
30
+ def method_that_class_colourise(message, failure)
31
+ colourise(message, failure)
32
+ end
33
+ end.new(@options, @io)
34
+ @failure = stub('failure', :pending_fixed? => false)
35
+ end
36
+
37
+ context "#colourise" do
38
+ it "warns when subclasses call colourise" do
39
+ Kernel.should_receive(:warn).with(/DEPRECATED/)
40
+ @formatter.method_that_class_colourise('this message', @failure)
41
+ end
42
+
43
+ it "delegates to colorize_failure" do
44
+ @formatter.should_receive(:colorize_failure).with('this message', @failure)
45
+ @formatter.colourise('this message', @failure)
46
+ end
47
+ end
48
+
49
+ context "#magenta" do
50
+ it "warns when subclasses call magenta" do
51
+ Kernel.should_receive(:warn).with(/DEPRECATED/)
52
+ @formatter.method_that_class_magenta('this message')
53
+ end
19
54
 
55
+ it "delegates to red" do
56
+ @formatter.should_receive(:red).with('this message')
57
+ @formatter.method_that_class_magenta('this message')
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ describe "#colour (protected)" do
64
+ before(:each) do
65
+ @original_RSPEC_COLOR = ENV['RSPEC_COLOR']
66
+ end
67
+
68
+ it "colorizes when colour? and output_to_tty? return true" do
69
+ out = StringIO.new
70
+ options = stub('options', :colour => true)
71
+ formatter = BaseTextFormatter.new(options,out)
72
+ formatter.stub!(:output_to_tty?).and_return(true)
73
+ formatter.__send__(:colour, 'foo', "\e[32m").should == "\e[32mfoo\e[0m"
74
+ end
75
+
76
+ it "colorizes when ENV['RSPEC_COLOR'] is set even if colour? and output_to_tty? return false" do
77
+ out = StringIO.new
78
+ options = stub('options', :colour => false)
79
+ formatter = BaseTextFormatter.new(options,out)
80
+ formatter.stub!(:output_to_tty?).and_return(false)
81
+
82
+ ENV['RSPEC_COLOR'] = 'true'
83
+
84
+ formatter.__send__(:colour, 'foo', "\e[32m").should == "\e[32mfoo\e[0m"
85
+ end
86
+
87
+ after(:each) do
88
+ ENV['RSPEC_COLOR'] = @original_RSPEC_COLOR
89
+ end
90
+ end
20
91
  end
21
92
  end
22
93
  end
@@ -15,11 +15,11 @@ module Spec
15
15
  end
16
16
 
17
17
  it "should add example name for each failure" do
18
- formatter.add_example_group(Class.new(ExampleGroup).describe("b 1"))
19
- formatter.example_failed("e 1", nil, Spec::Runner::Reporter::Failure.new(nil, RuntimeError.new))
20
- formatter.add_example_group(Class.new(ExampleGroup).describe("b 2"))
21
- formatter.example_failed("e 2", nil, Spec::Runner::Reporter::Failure.new(nil, RuntimeError.new))
22
- formatter.example_failed("e 3", nil, Spec::Runner::Reporter::Failure.new(nil, RuntimeError.new))
18
+ formatter.add_example_group(Class.new(::Spec::Example::ExampleGroupDouble).describe("b 1"))
19
+ formatter.example_failed("e 1", nil, Spec::Runner::Reporter::Failure.new("g", nil, RuntimeError.new))
20
+ formatter.add_example_group(Class.new(::Spec::Example::ExampleGroupDouble).describe("b 2"))
21
+ formatter.example_failed("e 2", nil, Spec::Runner::Reporter::Failure.new("g", nil, RuntimeError.new))
22
+ formatter.example_failed("e 3", nil, Spec::Runner::Reporter::Failure.new("g", nil, RuntimeError.new))
23
23
  io.string.should include("b 1")
24
24
  io.string.should include("b 2")
25
25
  end
@@ -30,13 +30,13 @@ module Spec
30
30
  grand_child_example_group = Class.new(child_example_group).describe("GrandChild")
31
31
 
32
32
  formatter.add_example_group(grand_child_example_group)
33
- formatter.example_failed("failure", nil, ::Spec::Runner::Reporter::Failure.new(nil, RuntimeError.new))
33
+ formatter.example_failed("failure", nil, ::Spec::Runner::Reporter::Failure.new("g", nil, RuntimeError.new))
34
34
  io.string.should == "Parent#child_method GrandChild\n"
35
35
  end
36
36
 
37
37
  it "should remove druby url, which is used by Spec::Distributed" do
38
- @formatter.add_example_group(Class.new(ExampleGroup).describe("something something (druby://99.99.99.99:99)"))
39
- @formatter.example_failed("e 1", nil, ::Spec::Runner::Reporter::Failure.new(nil, RuntimeError.new))
38
+ @formatter.add_example_group(Class.new(::Spec::Example::ExampleGroupDouble).describe("something something (druby://99.99.99.99:99)"))
39
+ @formatter.example_failed("e 1", nil, ::Spec::Runner::Reporter::Failure.new("g", nil, RuntimeError.new))
40
40
  io.string.should == "something something\n"
41
41
  end
42
42
  end