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
@@ -7,9 +7,7 @@ module Spec
7
7
 
8
8
  module Foo
9
9
  module Bar
10
- def self.loaded?
11
- true
12
- end
10
+ def self.loaded?; true; end
13
11
  end
14
12
  end
15
13
  include Foo
@@ -74,7 +72,7 @@ module Spec
74
72
  options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
75
73
  @reporter = FakeReporter.new(options)
76
74
  options.reporter = reporter
77
- @example_group = Class.new(ExampleGroup) do
75
+ @example_group = Class.new(ExampleGroupDouble) do
78
76
  describe("example")
79
77
  it "does nothing" do
80
78
  end
@@ -89,7 +87,7 @@ module Spec
89
87
  end
90
88
 
91
89
  it "should not run when there are no examples" do
92
- example_group = Class.new(ExampleGroup) do
90
+ example_group = Class.new(ExampleGroupDouble) do
93
91
  describe("Foobar")
94
92
  end
95
93
  example_group.examples.should be_empty
@@ -164,7 +162,7 @@ module Spec
164
162
  describe "when specified_examples matches entire ExampleGroup" do
165
163
  before do
166
164
  examples_that_were_run = @examples_that_were_run
167
- @example_group = Class.new(ExampleGroup) do
165
+ @example_group = Class.new(ExampleGroupDouble) do
168
166
  describe("the ExampleGroup")
169
167
  it("should be run") do
170
168
  examples_that_were_run << 'should be run'
@@ -186,7 +184,7 @@ module Spec
186
184
  describe ExampleGroup, "#run when specified_examples matches only Example description" do
187
185
  before do
188
186
  examples_that_were_run = @examples_that_were_run
189
- @example_group = Class.new(ExampleGroup) do
187
+ @example_group = Class.new(ExampleGroupDouble) do
190
188
  describe("example")
191
189
  it("should be run") do
192
190
  examples_that_were_run << 'should be run'
@@ -204,7 +202,7 @@ module Spec
204
202
  describe ExampleGroup, "#run when specified_examples does not match an Example description" do
205
203
  before do
206
204
  examples_that_were_run = @examples_that_were_run
207
- @example_group = Class.new(ExampleGroup) do
205
+ @example_group = Class.new(ExampleGroupDouble) do
208
206
  describe("example")
209
207
  it("should be something else") do
210
208
  examples_that_were_run << 'should be something else'
@@ -222,7 +220,7 @@ module Spec
222
220
  describe ExampleGroup, "#run when specified_examples matches an Example description" do
223
221
  before do
224
222
  examples_that_were_run = @examples_that_were_run
225
- @example_group = Class.new(ExampleGroup) do
223
+ @example_group = Class.new(ExampleGroupDouble) do
226
224
  describe("example")
227
225
  it("should be run") do
228
226
  examples_that_were_run << 'should be run'
@@ -234,22 +232,18 @@ module Spec
234
232
  options.parse_example "should be run"
235
233
  end
236
234
 
237
- it "should run only the example, when there is only one" do
235
+ it "should run only the example" do
238
236
  example_group.run(options)
239
237
  examples_that_were_run.should == ["should be run"]
240
238
  end
241
-
242
- it "should run only the one example" do
243
- example_group.run(options)
244
- examples_that_were_run.should == ["should be run"] end
245
239
  end
246
240
  end
247
241
 
248
242
  describe ExampleGroup, "#run with success" do
249
243
  before do
250
- @special_example_group = Class.new(ExampleGroup)
244
+ @special_example_group = Class.new(ExampleGroupDouble)
251
245
  ExampleGroupFactory.register(:special, @special_example_group)
252
- @not_special_example_group = Class.new(ExampleGroup)
246
+ @not_special_example_group = Class.new(ExampleGroupDouble)
253
247
  ExampleGroupFactory.register(:not_special, @not_special_example_group)
254
248
  end
255
249
 
@@ -317,7 +311,7 @@ module Spec
317
311
  @special_example_group.before(:all) { fiddle << "Example.before(:all, :type => :special)" }
318
312
  @special_example_group.prepend_before(:all) { fiddle << "Example.prepend_before(:all, :type => :special)" }
319
313
 
320
- example_group = Class.new(ExampleGroup) do
314
+ example_group = Class.new(ExampleGroupDouble) do
321
315
  describe("I'm not special", :type => :not_special)
322
316
  it "does nothing"
323
317
  end
@@ -434,47 +428,6 @@ module Spec
434
428
  example_group.included_modules.should_not include(mod3)
435
429
  end
436
430
 
437
- it "should include any predicate_matchers included using configuration" do
438
- $included_predicate_matcher_found = false
439
- Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
440
- example_group = Class.new(ExampleGroup) do
441
- describe('example')
442
- it "should respond to do_something" do
443
- $included_predicate_matcher_found = respond_to?(:do_something)
444
- end
445
- end
446
- example_group.run(options)
447
- $included_predicate_matcher_found.should be(true)
448
- end
449
-
450
- it "should use a mock framework set up in config" do
451
- mod = Module.new do
452
- def self.included(mod)
453
- $included_module = mod
454
- end
455
-
456
- def teardown_mocks_for_rspec
457
- $torn_down = true
458
- end
459
- end
460
-
461
- begin
462
- $included_module = nil
463
- $torn_down = true
464
- Spec::Runner.configuration.mock_with mod
465
-
466
- example_group = Class.new(ExampleGroup) do
467
- describe('example')
468
- it "does nothing"
469
- end
470
- example_group.run(options)
471
-
472
- $included_module.should_not be_nil
473
- $torn_down.should == true
474
- ensure
475
- Spec::Runner.configuration.mock_with :rspec
476
- end
477
- end
478
431
  end
479
432
 
480
433
  describe ExampleGroup, "#run with pending example that has a failing assertion" do
@@ -534,7 +487,7 @@ module Spec
534
487
  end
535
488
 
536
489
  it "should supply before(:all) as description" do
537
- @reporter.should_receive(:failure) do |example, error|
490
+ @reporter.should_receive(:example_failed) do |example, error|
538
491
  example.description.should eql("before(:all)")
539
492
  error.message.should eql("before(:all) failure")
540
493
  end
@@ -647,28 +600,16 @@ module Spec
647
600
  end
648
601
  end
649
602
 
650
- class ExampleSubclass < ExampleGroup
651
- end
652
-
653
603
  describe ExampleGroup, "subclasses" do
654
- after do
655
- ExampleGroupFactory.reset
656
- end
657
-
658
604
  it "should have access to the described_type" do
659
- example_group = Class.new(ExampleSubclass) do
660
- describe(Array)
661
- end
605
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
662
606
  example_group.__send__(:described_type).should == Array
663
607
  end
664
608
 
665
609
  it "should concat descriptions when nested" do
666
- example_group = Class.new(ExampleSubclass) do
667
- describe(Array)
668
- $nested_group = describe("when empty") do
669
- end
670
- end
671
- $nested_group.description.to_s.should == "Array when empty"
610
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
611
+ nested_group = example_group.describe("when empty") do; end
612
+ nested_group.description.to_s.should == "Array when empty"
672
613
  end
673
614
  end
674
615
  end
@@ -3,52 +3,52 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Example
5
5
  describe ExampleMatcher, "#matches?" do
6
- def match_description(description)
6
+ def match_examples(examples)
7
7
  simple_matcher do |actual, matcher|
8
8
  matcher.failure_message = "expected matcher.matches?(#{description.inspect}) to return true, got false"
9
9
  matcher.negative_failure_message = "expected matcher.matches?(#{description.inspect}) to return false, got true"
10
- actual.matches?(description)
10
+ actual.matches?(examples)
11
11
  end
12
12
  end
13
13
 
14
14
  it "should match correct example_group and example" do
15
15
  matcher = ExampleMatcher.new("example_group", "example")
16
- matcher.should match_description("example_group example")
16
+ matcher.should match_examples(["example_group example"])
17
17
  end
18
18
 
19
19
  it "should not match wrong example" do
20
20
  matcher = ExampleMatcher.new("example_group", "other example")
21
- matcher.should_not match_description("example_group example")
21
+ matcher.should_not match_examples(["example_group example"])
22
22
  end
23
23
 
24
24
  it "should not match wrong example_group" do
25
25
  matcher = ExampleMatcher.new("other example_group", "example")
26
- matcher.should_not match_description("example_group example")
26
+ matcher.should_not match_examples(["example_group example"])
27
27
  end
28
28
 
29
29
  it "should match example only" do
30
30
  matcher = ExampleMatcher.new("example_group", "example")
31
- matcher.should match_description("example")
31
+ matcher.should match_examples(["example"])
32
32
  end
33
33
 
34
34
  it "should match example_group only" do
35
35
  matcher = ExampleMatcher.new("example_group", "example")
36
- matcher.should match_description("example_group")
36
+ matcher.should match_examples(["example_group"])
37
37
  end
38
38
 
39
39
  it "should match example_group ending with before(:all)" do
40
40
  matcher = ExampleMatcher.new("example_group", "example")
41
- matcher.should match_description("example_group before(:all)")
41
+ matcher.should match_examples(["example_group before(:all)"])
42
42
  end
43
43
 
44
44
  it "should escape regexp chars" do
45
45
  matcher = ExampleMatcher.new("(con|text)", "[example]")
46
- matcher.should_not match_description("con p")
46
+ matcher.should_not match_examples(["con p"])
47
47
  end
48
48
 
49
49
  it "should match when example_group is modularized" do
50
50
  matcher = ExampleMatcher.new("MyModule::MyClass", "example")
51
- matcher.should match_description("MyClass example")
51
+ matcher.should match_examples(["MyClass example"])
52
52
  end
53
53
  end
54
54
 
@@ -2,287 +2,147 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  module Spec
4
4
  module Example
5
- module ModuleThatIsReopened
6
- end
5
+ describe ExampleMethods do
6
+ module ModuleThatIsReopened; end
7
7
 
8
- module ExampleMethods
9
- include ModuleThatIsReopened
10
- end
8
+ module ExampleMethods
9
+ include ModuleThatIsReopened
10
+ end
11
11
 
12
- module ModuleThatIsReopened
13
- def module_that_is_reopened_method
12
+ module ModuleThatIsReopened
13
+ def module_that_is_reopened_method; end
14
14
  end
15
- end
16
15
 
17
- describe ExampleMethods do
18
16
  describe "with an included module that is reopened" do
19
17
  it "should have repoened methods" do
20
18
  method(:module_that_is_reopened_method).should_not be_nil
21
19
  end
22
20
  end
23
21
 
24
- describe "lifecycle" do
25
- with_sandboxed_options do
26
- with_sandboxed_config do
27
- before do
28
- @options.formatters << mock("formatter", :null_object => true)
29
- @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
30
- @reporter = FakeReporter.new(@options)
31
- @options.reporter = @reporter
32
-
33
- ExampleGroup.before_all_parts.should == []
34
- ExampleGroup.before_each_parts.should == []
35
- ExampleGroup.after_each_parts.should == []
36
- ExampleGroup.after_all_parts.should == []
37
- def ExampleGroup.count
38
- @count ||= 0
39
- @count = @count + 1
40
- @count
41
- end
42
- end
43
- end
44
-
45
- after do
46
- ExampleGroup.instance_variable_set("@before_all_parts", [])
47
- ExampleGroup.instance_variable_set("@before_each_parts", [])
48
- ExampleGroup.instance_variable_set("@after_each_parts", [])
49
- ExampleGroup.instance_variable_set("@after_all_parts", [])
50
- end
51
-
52
- describe "eval_block" do
53
- before(:each) do
54
- @example_group = Class.new(ExampleGroup)
55
- end
56
-
57
- describe "with a given description" do
58
- it "should provide the given description" do
59
- @example = @example_group.it("given description") { 2.should == 2 }
60
- @example.eval_block
61
- @example.description.should == "given description"
62
- end
63
- end
64
-
65
- describe "with no given description" do
66
- it "should provide the generated description" do
67
- @example = @example_group.it { 2.should == 2 }
68
- @example.eval_block
69
- @example.description.should == "should == 2"
70
- end
71
- end
72
-
73
- describe "with no implementation" do
74
- it "should raise an NotYetImplementedError" do
75
- lambda {
76
- @example = @example_group.it
77
- @example.eval_block
78
- }.should raise_error(Spec::Example::NotYetImplementedError, "Not Yet Implemented")
79
- end
80
-
81
- def extract_error(&blk)
82
- begin
83
- blk.call
84
- rescue Exception => e
85
- return e
86
- end
87
-
88
- nil
89
- end
90
-
91
- it "should use the proper file and line number for the NotYetImplementedError" do
92
- file = __FILE__
93
- line_number = __LINE__ + 3
94
-
95
- error = extract_error do
96
- @example = @example_group.it
97
- @example.eval_block
98
- end
99
-
100
- error.pending_caller.should =~ /#{file}:#{line_number}/
101
- end
102
- end
103
- end
104
- end
105
- end
106
-
107
22
  describe "#backtrace" do
108
- with_sandboxed_options do
109
- it "returns the backtrace from where the example was defined" do
110
- example_group = Class.new(ExampleGroup) do
111
- example "of something" do; end
112
- end
113
-
114
- example = example_group.examples.first
115
- example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
116
- end
23
+ it "returns the backtrace from where the example was defined" do
24
+ example = ExampleGroup.dup.new "name"
25
+ example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
117
26
  end
118
27
  end
119
28
 
120
29
  describe "#implementation_backtrace (deprecated)" do
121
- with_sandboxed_options do
122
- before(:each) do
123
- Kernel.stub!(:warn)
124
- end
30
+ before(:each) do
31
+ Kernel.stub!(:warn)
32
+ end
125
33
 
126
- it "sends a deprecation warning" do
127
- example_group = Class.new(ExampleGroup) {}
128
- example = example_group.example("") {}
129
- Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m)
130
- example.implementation_backtrace
131
- end
132
-
133
- it "returns the backtrace from where the example was defined" do
134
- example_group = Class.new(ExampleGroup) do
135
- example "of something" do; end
136
- end
137
-
138
- example = example_group.examples.first
139
- example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
140
- end
34
+ it "sends a deprecation warning" do
35
+ Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m)
36
+ example = ExampleGroup.dup.new "name"
37
+ example.implementation_backtrace
38
+ end
39
+
40
+ it "returns the backtrace from where the example was defined" do
41
+ example = ExampleGroup.dup.new "name"
42
+ example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
141
43
  end
142
44
  end
143
45
 
144
- describe "#full_description" do
145
- it "should return the full description of the ExampleGroup and Example" do
146
- example_group = Class.new(ExampleGroup).describe("An ExampleGroup") do
147
- it "should do something" do
148
- end
149
- end
150
- example = example_group.examples.first
151
- example.full_description.should == "An ExampleGroup should do something"
46
+ describe "#subject" do
47
+ before(:each) do
48
+ @example_group = ExampleGroupDouble
49
+ end
50
+
51
+ it "should return an instance of the described class" do
52
+ group = Class.new(ExampleGroupDouble).describe(Array)
53
+ example = group.new("")
54
+ example.subject.should == []
55
+ end
56
+
57
+ it "should return nil for a module (as opposed to a class)" do
58
+ group = Class.new(ExampleGroupDouble).describe(Enumerable)
59
+ example = group.new("")
60
+ example.subject.should be_nil
61
+ end
62
+
63
+ it "should return nil for a string" do
64
+ group = Class.new(ExampleGroupDouble).describe('foo')
65
+ example = group.new("")
66
+ example.subject.should be_nil
152
67
  end
153
68
  end
154
-
155
- describe "#subject" do
156
- with_sandboxed_options do
157
- it "should return an instance variable named after the described type" do
158
- example_group = Class.new(ExampleGroup).describe(Array) do
159
- example {}
160
- end
161
- example = example_group.examples.first
162
- example.subject.should == []
163
- end
164
-
165
- it "should not barf on a module (as opposed to a class)" do
166
- example_group = Class.new(ExampleGroup).describe(ObjectSpace) do
167
- example {}
168
- end
169
- example_group.examples.first.subject.should be_nil
170
- end
171
-
172
- it "should not barf on a string" do
173
- example_group = Class.new(ExampleGroup).describe('foo') do
174
- example {}
175
- end
176
- example_group.examples.first.subject.should be_nil
177
- end
178
-
179
- it "should interact with the same scope as the before block" do
180
- example_group = Class.new(ExampleGroup) do
181
- subject { @foo = 'foo'}
182
- example { should == @foo}
183
- it { should == 'foo'}
184
- end
185
- example_group.run(options).should be_true
186
- end
69
+
70
+ class Thing
71
+ attr_reader :arg
72
+ def initialize(arg=nil)
73
+ @arg = arg || :default
74
+ end
75
+ def ==(other)
76
+ @arg == other.arg
77
+ end
78
+ def eql?(other)
79
+ @arg == other.arg
187
80
  end
188
81
  end
189
82
 
190
83
  describe "#should" do
191
- with_sandboxed_options do
192
- class Thing
193
- def ==(other)
194
- true
195
- end
196
- end
197
-
198
- describe "in an ExampleGroup with the ivar defined in before" do
199
- attr_reader :example, :success
200
-
201
- before(:each) do
202
- example_group = describe(Thing, "1") do
203
- before(:each) { @spec_example_thing = 'expected' }
204
- it { should eql('expected') }
205
- end
206
- @example = example_group.examples.first
207
- @success = example_group.run(options)
208
- end
209
-
210
- it "should create an example using the description from the matcher" do
211
- example.description.should == 'should eql "expected"'
212
- end
213
-
214
- it "should test the matcher returned from the block" do
215
- success.should be_true
216
- end
217
- end
218
-
219
- describe "in an ExampleGroup with the subject defined using #subject" do
220
- it "should create an example using the description from the matcher" do
221
- example_group = describe(Thing, "2") do
222
- subject {'this is the subject'}
223
- it { should eql('this is the subject') }
224
- end
225
- example = example_group.examples.first
226
- example_group.run(options)
227
- example.description.should =~ /should eql "this is the subject"/
228
- end
229
- end
230
-
231
- describe "in an ExampleGroup using an implicit ivar" do
232
- it "should create an example using the description from the matcher" do
233
- example_group = describe(Thing, "3") do
234
- it { should == Thing.new }
235
- end
236
- example = example_group.examples.first
237
- success = example_group.run(options)
238
- example.description.should =~ /should == #<Spec::Example::Thing/
239
- success.should be_true
240
- end
84
+ before(:each) do
85
+ @example_group = Class.new(ExampleGroupDouble)
86
+ @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
87
+ end
88
+
89
+ context "in an ExampleGroup with an implicit subject" do
90
+ it "delegates matcher to the implied subject" do
91
+ @example_group.describe(Thing)
92
+ @example_group.example { should == Thing.new(:default) }
93
+ @example_group.example { should eql(Thing.new(:default)) }
94
+ @example_group.run(@options).should be_true
241
95
  end
242
-
243
- after(:each) do
244
- ExampleGroup.reset
96
+ end
97
+
98
+ context "in an ExampleGroup using an explicit subject" do
99
+ it "delegates matcher to the declared subject" do
100
+ @example_group.describe(Thing)
101
+ @example_group.subject { Thing.new(:other) }
102
+ @example_group.example { should == Thing.new(:other) }
103
+ @example_group.example { should eql(Thing.new(:other)) }
104
+ @example_group.run(@options).should be_true
245
105
  end
246
-
247
106
  end
248
107
  end
249
108
 
250
109
  describe "#should_not" do
251
- with_sandboxed_options do
252
-
253
- attr_reader :example_group, :example, :success
254
-
255
- before do
256
- @example_group = Class.new(ExampleGroup) do
257
- def subject; @actual; end
258
- before(:each) { @actual = 'expected' }
259
- it { should_not eql('unexpected') }
260
- end
261
- @example = @example_group.examples.first
262
-
263
- @success = example_group.run(options)
264
- end
265
-
266
- it "should create an example using the description from the matcher" do
267
- example.description.should == 'should not eql "unexpected"'
268
- end
110
+ before(:each) do
111
+ @example_group = Class.new(ExampleGroupDouble)
112
+ end
269
113
 
270
- it "should test the matcher returned from the block" do
271
- success.should be_true
114
+ context "in an ExampleGroup with an implicit subject" do
115
+ it "delegates matcher to the implied subject" do
116
+ @example_group.describe(Thing)
117
+ @example_group.example { should_not == Thing.new(:other) }
118
+ @example_group.example { should_not eql(Thing.new(:other)) }
119
+ @example_group.run(::Spec::Runner::Options.new(StringIO.new, StringIO.new)).should be_true
272
120
  end
273
-
274
- after do
275
- ExampleGroup.reset
121
+ end
122
+
123
+ context "in an ExampleGroup using an explicit subject" do
124
+ it "delegates matcher to the declared subject" do
125
+ @example_group.describe(Thing)
126
+ @example_group.subject { Thing.new(:other) }
127
+ @example_group.example { should_not == Thing.new(:default) }
128
+ @example_group.example { should_not eql(Thing.new(:default)) }
129
+ @example_group.run(::Spec::Runner::Options.new(StringIO.new, StringIO.new)).should be_true
276
130
  end
277
-
278
131
  end
279
132
  end
280
133
  end
281
134
 
282
135
  describe "#options" do
283
136
  it "should expose the options hash" do
284
- example_group = Class.new(ExampleGroup)
285
- example = example_group.example "name", :this => 'that' do; end
137
+ example = ExampleGroupDouble.new "name", :this => 'that' do; end
138
+ example.options[:this].should == 'that'
139
+ end
140
+ end
141
+
142
+ describe "#set_instance_variables_from_hash" do
143
+ it "preserves the options" do
144
+ example = ExampleGroupDouble.new "name", :this => 'that' do; end
145
+ example.set_instance_variables_from_hash({:@_options => {}})
286
146
  example.options[:this].should == 'that'
287
147
  end
288
148
  end
@@ -59,11 +59,11 @@ module Spec
59
59
  describe "Nested Example Groups" do
60
60
  describe "description options", :other_options => "other options" do
61
61
  it "should have a spec_path" do
62
- self.class.description_options[:spec_path].should match(/#{__FILE__}/)
62
+ self.class.options[:spec_path].should match(/#{__FILE__}/)
63
63
  end
64
64
 
65
65
  it "should pass other options" do
66
- self.class.description_options[:other_options].should == "other options"
66
+ self.class.options[:other_options].should == "other options"
67
67
  end
68
68
  end
69
69
  end
@@ -52,7 +52,7 @@ module Spec
52
52
  begin
53
53
  pending("TODO")
54
54
  rescue => error
55
- error.pending_caller.should == "#{file}:#{line_number}"
55
+ error.pending_caller.should =~ /^#{file}:#{line_number}/
56
56
  end
57
57
  end
58
58
  end