dchelimsky-rspec 1.1.10 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/History.txt +17 -0
  2. data/Manifest.txt +53 -74
  3. data/Rakefile +0 -1
  4. data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
  5. data/examples/{pure → passing}/before_and_after_example.rb +0 -0
  6. data/examples/{pure → passing}/behave_as_example.rb +0 -0
  7. data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
  8. data/examples/{pure → passing}/custom_formatter.rb +1 -1
  9. data/examples/{pure → passing}/dynamic_spec.rb +2 -2
  10. data/examples/{pure → passing}/file_accessor.rb +0 -0
  11. data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
  12. data/examples/{pure → passing}/greeter_spec.rb +0 -0
  13. data/examples/{pure → passing}/helper_method_example.rb +0 -0
  14. data/examples/{pure → passing}/io_processor.rb +0 -0
  15. data/examples/{pure → passing}/io_processor_spec.rb +0 -0
  16. data/examples/{pure → passing}/legacy_spec.rb +0 -0
  17. data/examples/{pure → passing}/mocking_example.rb +0 -0
  18. data/examples/{pure → passing}/multi_threaded_behaviour_runner.rb +0 -0
  19. data/examples/{pure → passing}/nested_classes_example.rb +0 -0
  20. data/examples/{pure → passing}/partial_mock_example.rb +0 -0
  21. data/examples/{pure → passing}/pending_example.rb +0 -0
  22. data/examples/{pure → passing}/predicate_example.rb +0 -0
  23. data/examples/{pure → passing}/priority.txt +0 -0
  24. data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
  25. data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
  26. data/examples/{pure → passing}/spec_helper.rb +0 -0
  27. data/examples/{pure → passing}/stack.rb +0 -0
  28. data/examples/{pure → passing}/stack_spec.rb +3 -2
  29. data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
  30. data/examples/{pure → passing}/stubbing_example.rb +0 -0
  31. data/examples/{pure → passing}/yielding_example.rb +0 -0
  32. data/lib/spec/example/before_and_after_hooks.rb +8 -21
  33. data/lib/spec/example/configuration.rb +45 -45
  34. data/lib/spec/example/example_group_factory.rb +10 -9
  35. data/lib/spec/example/example_group_methods.rb +31 -15
  36. data/lib/spec/example/example_methods.rb +74 -22
  37. data/lib/spec/example/shared_example_group.rb +27 -16
  38. data/lib/spec/example.rb +28 -0
  39. data/lib/spec/expectations.rb +1 -0
  40. data/lib/spec/extensions.rb +0 -2
  41. data/lib/spec/matchers/be.rb +96 -114
  42. data/lib/spec/matchers/operator_matcher.rb +2 -9
  43. data/lib/spec/matchers/throw_symbol.rb +41 -15
  44. data/lib/spec/matchers.rb +4 -27
  45. data/lib/spec/runner/formatter/base_text_formatter.rb +1 -1
  46. data/lib/spec/runner/option_parser.rb +2 -2
  47. data/lib/spec/runner/reporter.rb +1 -1
  48. data/lib/spec/runner.rb +1 -1
  49. data/lib/spec/version.rb +1 -1
  50. data/lib/spec.rb +1 -0
  51. data/rspec.gemspec +4 -24
  52. data/spec/spec/example/example_group_factory_spec.rb +29 -9
  53. data/spec/spec/example/example_group_methods_spec.rb +4 -6
  54. data/spec/spec/example/example_group_spec.rb +0 -6
  55. data/spec/spec/example/example_matcher_spec.rb +6 -23
  56. data/spec/spec/example/example_methods_spec.rb +117 -2
  57. data/spec/spec/example/shared_example_group_spec.rb +51 -75
  58. data/spec/spec/matchers/be_spec.rb +40 -7
  59. data/spec/spec/matchers/description_generation_spec.rb +14 -0
  60. data/spec/spec/matchers/throw_symbol_spec.rb +83 -41
  61. data/spec/spec/runner/command_line_spec.rb +4 -4
  62. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
  63. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
  64. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
  65. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
  66. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +6 -6
  67. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -1
  68. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +5 -5
  69. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
  70. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +6 -6
  71. data/spec/spec/runner/reporter_spec.rb +1 -1
  72. data/stories/example_groups/autogenerated_docstrings +4 -4
  73. data/stories/example_groups/nested_groups +2 -2
  74. metadata +33 -59
  75. data/examples/stories/adder.rb +0 -13
  76. data/examples/stories/addition +0 -34
  77. data/examples/stories/addition.rb +0 -9
  78. data/examples/stories/calculator.rb +0 -65
  79. data/examples/stories/game-of-life/.loadpath +0 -5
  80. data/examples/stories/game-of-life/README.txt +0 -21
  81. data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
  82. data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
  83. data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
  84. data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
  85. data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
  86. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
  87. data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
  88. data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
  89. data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
  90. data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
  91. data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
  92. data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
  93. data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
  94. data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
  95. data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
  96. data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
  97. data/examples/stories/game-of-life/life/game.rb +0 -23
  98. data/examples/stories/game-of-life/life/grid.rb +0 -43
  99. data/examples/stories/game-of-life/life.rb +0 -3
  100. data/examples/stories/helper.rb +0 -9
  101. data/examples/stories/steps/addition_steps.rb +0 -18
  102. data/failing_examples/README.txt +0 -7
  103. data/failing_examples/diffing_spec.rb +0 -36
  104. data/failing_examples/failing_autogenerated_docstrings_example.rb +0 -19
  105. data/failing_examples/failure_in_setup.rb +0 -10
  106. data/failing_examples/failure_in_teardown.rb +0 -10
  107. data/failing_examples/mocking_example.rb +0 -40
  108. data/failing_examples/mocking_with_flexmock.rb +0 -26
  109. data/failing_examples/mocking_with_mocha.rb +0 -25
  110. data/failing_examples/mocking_with_rr.rb +0 -27
  111. data/failing_examples/partial_mock_example.rb +0 -20
  112. data/failing_examples/predicate_example.rb +0 -29
  113. data/failing_examples/raising_example.rb +0 -47
  114. data/failing_examples/spec_helper.rb +0 -3
  115. data/failing_examples/syntax_error_example.rb +0 -7
  116. data/failing_examples/team_spec.rb +0 -44
  117. data/failing_examples/timeout_behaviour.rb +0 -7
  118. data/lib/spec/extensions/main.rb +0 -87
  119. data/lib/spec/extensions/object.rb +0 -6
  120. data/spec/spec/extensions/main_spec.rb +0 -71
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ === Maintenance
2
+
3
+ * 2 major enhancements
4
+
5
+ * it { should matcher } - syntax support from Joe Ferris
6
+ * wrap_expectation (for wrapping multiple expectations and/or t/u assertions)
7
+
8
+ * 1 minor enhancement
9
+
10
+ * should throw_symbol accepts an optional argument: should throw_symbol(:sym, arg)
11
+
12
+ === Version 1.1.11 / 2008-10-24
13
+
14
+ * 1 major enhancement
15
+
16
+ * eliminate ALL gem dependencies (as they were causing trouble for people on different platforms/environments)
17
+
1
18
  === Version 1.1.10 / 2008-10-24
2
19
 
3
20
  * 1 minor enhancement
data/Manifest.txt CHANGED
@@ -1,3 +1,4 @@
1
+ .autotest
1
2
  History.txt
2
3
  License.txt
3
4
  Manifest.txt
@@ -6,77 +7,50 @@ Rakefile
6
7
  TODO.txt
7
8
  bin/autospec
8
9
  bin/spec
9
- examples/pure/autogenerated_docstrings_example.rb
10
- examples/pure/before_and_after_example.rb
11
- examples/pure/behave_as_example.rb
12
- examples/pure/custom_expectation_matchers.rb
13
- examples/pure/custom_formatter.rb
14
- examples/pure/dynamic_spec.rb
15
- examples/pure/file_accessor.rb
16
- examples/pure/file_accessor_spec.rb
17
- examples/pure/greeter_spec.rb
18
- examples/pure/helper_method_example.rb
19
- examples/pure/io_processor.rb
20
- examples/pure/io_processor_spec.rb
21
- examples/pure/legacy_spec.rb
22
- examples/pure/mocking_example.rb
23
- examples/pure/multi_threaded_behaviour_runner.rb
24
- examples/pure/nested_classes_example.rb
25
- examples/pure/partial_mock_example.rb
26
- examples/pure/pending_example.rb
27
- examples/pure/predicate_example.rb
28
- examples/pure/priority.txt
29
- examples/pure/shared_example_group_example.rb
30
- examples/pure/shared_stack_examples.rb
31
- examples/pure/spec_helper.rb
32
- examples/pure/stack.rb
33
- examples/pure/stack_spec.rb
34
- examples/pure/stack_spec_with_nested_example_groups.rb
35
- examples/pure/stubbing_example.rb
36
- examples/pure/yielding_example.rb
37
- examples/stories/adder.rb
38
- examples/stories/addition
39
- examples/stories/addition.rb
40
- examples/stories/calculator.rb
41
- examples/stories/game-of-life/.loadpath
42
- examples/stories/game-of-life/README.txt
43
- examples/stories/game-of-life/behaviour/everything.rb
44
- examples/stories/game-of-life/behaviour/examples/examples.rb
45
- examples/stories/game-of-life/behaviour/examples/game_behaviour.rb
46
- examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
47
- examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story
48
- examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story
49
- examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story
50
- examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story
51
- examples/stories/game-of-life/behaviour/stories/ICanKillACell.story
52
- examples/stories/game-of-life/behaviour/stories/TheGridWraps.story
53
- examples/stories/game-of-life/behaviour/stories/create_a_cell.rb
54
- examples/stories/game-of-life/behaviour/stories/helper.rb
55
- examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb
56
- examples/stories/game-of-life/behaviour/stories/steps.rb
57
- examples/stories/game-of-life/behaviour/stories/stories.rb
58
- examples/stories/game-of-life/behaviour/stories/stories.txt
59
- examples/stories/game-of-life/life.rb
60
- examples/stories/game-of-life/life/game.rb
61
- examples/stories/game-of-life/life/grid.rb
62
- examples/stories/helper.rb
63
- examples/stories/steps/addition_steps.rb
64
- failing_examples/README.txt
65
- failing_examples/diffing_spec.rb
66
- failing_examples/failing_autogenerated_docstrings_example.rb
67
- failing_examples/failure_in_setup.rb
68
- failing_examples/failure_in_teardown.rb
69
- failing_examples/mocking_example.rb
70
- failing_examples/mocking_with_flexmock.rb
71
- failing_examples/mocking_with_mocha.rb
72
- failing_examples/mocking_with_rr.rb
73
- failing_examples/partial_mock_example.rb
74
- failing_examples/predicate_example.rb
75
- failing_examples/raising_example.rb
76
- failing_examples/spec_helper.rb
77
- failing_examples/syntax_error_example.rb
78
- failing_examples/team_spec.rb
79
- failing_examples/timeout_behaviour.rb
10
+ examples/failing/README.txt
11
+ examples/failing/diffing_spec.rb
12
+ examples/failing/failing_autogenerated_docstrings_example.rb
13
+ examples/failing/failure_in_setup.rb
14
+ examples/failing/failure_in_teardown.rb
15
+ examples/failing/mocking_example.rb
16
+ examples/failing/mocking_with_flexmock.rb
17
+ examples/failing/mocking_with_mocha.rb
18
+ examples/failing/mocking_with_rr.rb
19
+ examples/failing/partial_mock_example.rb
20
+ examples/failing/predicate_example.rb
21
+ examples/failing/raising_example.rb
22
+ examples/failing/spec_helper.rb
23
+ examples/failing/syntax_error_example.rb
24
+ examples/failing/team_spec.rb
25
+ examples/failing/timeout_behaviour.rb
26
+ examples/passing/autogenerated_docstrings_example.rb
27
+ examples/passing/before_and_after_example.rb
28
+ examples/passing/behave_as_example.rb
29
+ examples/passing/custom_expectation_matchers.rb
30
+ examples/passing/custom_formatter.rb
31
+ examples/passing/dynamic_spec.rb
32
+ examples/passing/file_accessor.rb
33
+ examples/passing/file_accessor_spec.rb
34
+ examples/passing/greeter_spec.rb
35
+ examples/passing/helper_method_example.rb
36
+ examples/passing/io_processor.rb
37
+ examples/passing/io_processor_spec.rb
38
+ examples/passing/legacy_spec.rb
39
+ examples/passing/mocking_example.rb
40
+ examples/passing/multi_threaded_behaviour_runner.rb
41
+ examples/passing/nested_classes_example.rb
42
+ examples/passing/partial_mock_example.rb
43
+ examples/passing/pending_example.rb
44
+ examples/passing/predicate_example.rb
45
+ examples/passing/priority.txt
46
+ examples/passing/shared_example_group_example.rb
47
+ examples/passing/shared_stack_examples.rb
48
+ examples/passing/spec_helper.rb
49
+ examples/passing/stack.rb
50
+ examples/passing/stack_spec.rb
51
+ examples/passing/stack_spec_with_nested_example_groups.rb
52
+ examples/passing/stubbing_example.rb
53
+ examples/passing/yielding_example.rb
80
54
  init.rb
81
55
  lib/autotest/discover.rb
82
56
  lib/autotest/rspec.rb
@@ -85,6 +59,8 @@ lib/spec/adapters.rb
85
59
  lib/spec/adapters/ruby_engine.rb
86
60
  lib/spec/adapters/ruby_engine/mri.rb
87
61
  lib/spec/adapters/ruby_engine/rubinius.rb
62
+ lib/spec/dsl.rb
63
+ lib/spec/dsl/main.rb
88
64
  lib/spec/example.rb
89
65
  lib/spec/example/before_and_after_hooks.rb
90
66
  lib/spec/example/configuration.rb
@@ -104,11 +80,10 @@ lib/spec/expectations/extensions.rb
104
80
  lib/spec/expectations/extensions/object.rb
105
81
  lib/spec/expectations/extensions/string_and_symbol.rb
106
82
  lib/spec/expectations/handler.rb
83
+ lib/spec/expectations/wrap_expectation.rb
107
84
  lib/spec/extensions.rb
108
85
  lib/spec/extensions/class.rb
109
- lib/spec/extensions/main.rb
110
86
  lib/spec/extensions/metaclass.rb
111
- lib/spec/extensions/object.rb
112
87
  lib/spec/interop/test.rb
113
88
  lib/spec/interop/test/unit/autorunner.rb
114
89
  lib/spec/interop/test/unit/testcase.rb
@@ -121,11 +96,14 @@ lib/spec/matchers/be_close.rb
121
96
  lib/spec/matchers/change.rb
122
97
  lib/spec/matchers/eql.rb
123
98
  lib/spec/matchers/equal.rb
99
+ lib/spec/matchers/errors.rb
124
100
  lib/spec/matchers/exist.rb
101
+ lib/spec/matchers/generated_descriptions.rb
125
102
  lib/spec/matchers/has.rb
126
103
  lib/spec/matchers/have.rb
127
104
  lib/spec/matchers/include.rb
128
105
  lib/spec/matchers/match.rb
106
+ lib/spec/matchers/method_missing.rb
129
107
  lib/spec/matchers/operator_matcher.rb
130
108
  lib/spec/matchers/raise_error.rb
131
109
  lib/spec/matchers/respond_to.rb
@@ -213,6 +191,7 @@ spec/rspec_suite.rb
213
191
  spec/ruby_forker.rb
214
192
  spec/spec.opts
215
193
  spec/spec/adapters/ruby_engine_spec.rb
194
+ spec/spec/dsl/main_spec.rb
216
195
  spec/spec/example/configuration_spec.rb
217
196
  spec/spec/example/example_group_class_definition_spec.rb
218
197
  spec/spec/example/example_group_factory_spec.rb
@@ -229,7 +208,7 @@ spec/spec/example/subclassing_example_group_spec.rb
229
208
  spec/spec/expectations/differs/default_spec.rb
230
209
  spec/spec/expectations/extensions/object_spec.rb
231
210
  spec/spec/expectations/fail_with_spec.rb
232
- spec/spec/extensions/main_spec.rb
211
+ spec/spec/expectations/wrap_expectation_spec.rb
233
212
  spec/spec/interop/test/unit/resources/spec_that_fails.rb
234
213
  spec/spec/interop/test/unit/resources/spec_that_passes.rb
235
214
  spec/spec/interop/test/unit/resources/spec_with_errors.rb
data/Rakefile CHANGED
@@ -18,7 +18,6 @@ Hoe.new('rspec', Spec::VERSION::STRING) do |p|
18
18
  p.url = 'http://rspec.info/'
19
19
  p.description = "Behaviour Driven Development for Ruby."
20
20
  p.rubyforge_name = 'rspec'
21
- p.extra_dev_deps = ['diff-lcs','syntax']
22
21
  p.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
23
22
  p.remote_rdoc_dir = "rspec/#{Spec::VERSION::STRING}"
24
23
  end
@@ -17,3 +17,9 @@ describe "Examples with no descriptions" do
17
17
  specify { [1,2,3].should respond_to(:size) }
18
18
 
19
19
  end
20
+
21
+ describe "the number 1" do
22
+ subject { 1 }
23
+ it { should == 1 }
24
+ it { should be < 2}
25
+ end
File without changes
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
  require 'spec/runner/formatter/progress_bar_formatter'
3
3
 
4
4
  # Example of a formatter with custom bactrace printing. Run me with:
5
- # ruby bin/spec failing_examples -r examples/custom_formatter.rb -f CustomFormatter
5
+ # ruby bin/spec examples/failing -r examples/custom_formatter.rb -f CustomFormatter
6
6
  class CustomFormatter < Spec::Runner::Formatter::ProgressBarFormatter
7
7
  def backtrace_line(line)
8
8
  line.gsub(/([^:]*\.rb):(\d*)/) do
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe "Some integers" do
3
+ describe "The square root" do
4
4
  (1..10).each do |n|
5
- it "The root of #{n} square should be #{n}" do
5
+ it "of #{n*n} should be #{n}" do
6
6
  Math.sqrt(n*n).should == n
7
7
  end
8
8
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,3 @@
1
- require File.join(File.dirname(__FILE__), *%w[spec_helper])
2
-
3
1
  shared_examples_for "non-empty Stack" do
4
2
 
5
3
  it { @stack.should_not be_empty }
@@ -7,7 +5,7 @@ shared_examples_for "non-empty Stack" do
7
5
  it "should return the top item when sent #peek" do
8
6
  @stack.peek.should == @last_item_added
9
7
  end
10
-
8
+
11
9
  it "should NOT remove the top item when sent #peek" do
12
10
  @stack.peek.should == @last_item_added
13
11
  @stack.peek.should == @last_item_added
File without changes
File without changes
@@ -7,8 +7,9 @@ describe Stack, " (empty)" do
7
7
  @stack = Stack.new
8
8
  end
9
9
 
10
- # NOTE that this one auto-generates the description "should be empty"
11
- it { @stack.should be_empty }
10
+ # This uses @stack (because the described class is Stack) auto-generates the
11
+ # description "should be empty"
12
+ it { should be_empty }
12
13
 
13
14
  it_should_behave_like "non-full Stack"
14
15
 
File without changes
File without changes
@@ -4,35 +4,27 @@ module Spec
4
4
  # Registers a block to be executed before each example.
5
5
  # This method prepends +block+ to existing before blocks.
6
6
  def prepend_before(*args, &block)
7
- scope, options = scope_and_options(*args)
8
- parts = before_parts_from_scope(scope)
9
- parts.unshift(block)
7
+ before_parts(*args).unshift(block)
10
8
  end
11
9
 
12
10
  # Registers a block to be executed before each example.
13
11
  # This method appends +block+ to existing before blocks.
14
12
  def append_before(*args, &block)
15
- scope, options = scope_and_options(*args)
16
- parts = before_parts_from_scope(scope)
17
- parts << block
13
+ before_parts(*args) << block
18
14
  end
19
15
  alias_method :before, :append_before
20
16
 
21
17
  # Registers a block to be executed after each example.
22
18
  # This method prepends +block+ to existing after blocks.
23
19
  def prepend_after(*args, &block)
24
- scope, options = scope_and_options(*args)
25
- parts = after_parts_from_scope(scope)
26
- parts.unshift(block)
20
+ after_parts(*args).unshift(block)
27
21
  end
28
22
  alias_method :after, :prepend_after
29
23
 
30
24
  # Registers a block to be executed after each example.
31
25
  # This method appends +block+ to existing after blocks.
32
26
  def append_after(*args, &block)
33
- scope, options = scope_and_options(*args)
34
- parts = after_parts_from_scope(scope)
35
- parts << block
27
+ after_parts(*args) << block
36
28
  end
37
29
 
38
30
  def remove_after(scope, &block)
@@ -67,21 +59,16 @@ module Spec
67
59
 
68
60
  private
69
61
 
70
- def scope_and_options(*args)
71
- args, options = args_and_options(*args)
72
- scope = (args[0] || :each), options
73
- end
74
-
75
- def before_parts_from_scope(scope)
76
- case scope
62
+ def before_parts(*args)
63
+ case Spec::Example.scope_from(*args)
77
64
  when :each; before_each_parts
78
65
  when :all; before_all_parts
79
66
  when :suite; Spec::Runner.options.before_suite_parts
80
67
  end
81
68
  end
82
69
 
83
- def after_parts_from_scope(scope)
84
- case scope
70
+ def after_parts(*args)
71
+ case Spec::Example.scope_from(*args)
85
72
  when :each; after_each_parts
86
73
  when :all; after_all_parts
87
74
  when :suite; Spec::Runner.options.after_suite_parts
@@ -47,44 +47,48 @@ module Spec
47
47
  # include(My::Helpers, :type => :key)
48
48
  #
49
49
  # Declares modules to be included in multiple example groups
50
- # (<tt>describe</tt> blocks). With no :type, the modules listed will be
51
- # included in all example groups. Use :type to restrict the inclusion to
52
- # a subset of example groups. The value assigned to :type should be a
53
- # key that maps to a class that is either a subclass of
54
- # Spec::Example::ExampleGroup or extends Spec::Example::ExampleGroupMethods
55
- # and includes Spec::Example::ExampleMethods
50
+ # (<tt>describe</tt> blocks). With no <tt>:type</tt>, the modules listed
51
+ # will be included in all example groups.
56
52
  #
57
- # config.include(My::Pony, My::Horse, :type => :farm)
53
+ # Use <tt>:type</tt> to restrict
54
+ # the inclusion to a subset of example groups. The value assigned to
55
+ # <tt>:type</tt> should be a key that maps to a class that is either a
56
+ # subclass of Spec::Example::ExampleGroup or extends
57
+ # Spec::Example::ExampleGroupMethods and includes
58
+ # Spec::Example::ExampleMethods.
59
+ #
60
+ # For example, the rspec-rails gem/plugin extends Test::Unit::TestCase
61
+ # with Spec::Example::ExampleGroupMethods and includes
62
+ # Spec::Example::ExampleMethods in it. So if you have a module of helper
63
+ # methods for controller examples, you could do this:
64
+ #
65
+ # config.include(ControllerExampleHelpers, :type => :controller)
58
66
  #
59
67
  # Only example groups that have that type will get the modules included:
60
68
  #
61
- # describe "Downtown", :type => :city do
62
- # # Will *not* get My::Pony and My::Horse included
69
+ # describe Account, :type => :model do
70
+ # # Will *not* include ControllerExampleHelpers
63
71
  # end
64
72
  #
65
- # describe "Old Mac Donald", :type => :farm do
66
- # # *Will* get My::Pony and My::Horse included
73
+ # describe AccountsController, :type => :controller do
74
+ # # *Will* include ControllerExampleHelpers
67
75
  # end
68
76
  #
69
77
  def include(*args)
70
78
  include_or_extend(:include, *args)
71
79
  end
72
80
 
81
+ # :call-seq:
82
+ # extend(Some::Helpers)
83
+ # extend(Some::Helpers, More::Helpers)
84
+ # extend(My::Helpers, :type => :key)
85
+ #
86
+ # Works just like #include, but extends the example groups
87
+ # with the modules rather than including them.
73
88
  def extend(*args)
74
89
  include_or_extend(:extend, *args)
75
90
  end
76
91
 
77
- def include_or_extend(*args)
78
- action = args.shift
79
- args << {} unless Hash === args.last
80
- modules, options = args_and_options(*args)
81
- required_example_group = get_type_from_options(options)
82
- required_example_group = required_example_group.to_sym if required_example_group
83
- modules.each do |mod|
84
- ExampleGroupFactory.get(required_example_group).send(action, mod)
85
- end
86
- end
87
-
88
92
  # Defines global predicate matchers. Example:
89
93
  #
90
94
  # config.predicate_matchers[:swim] = :can_swim?
@@ -100,11 +104,7 @@ module Spec
100
104
  # Prepends a global <tt>before</tt> block to all example groups.
101
105
  # See #append_before for filtering semantics.
102
106
  def prepend_before(*args, &proc)
103
- scope, options = scope_and_options(*args)
104
- example_group = ExampleGroupFactory.get(
105
- get_type_from_options(options)
106
- )
107
- example_group.prepend_before(scope, &proc)
107
+ add_callback(:prepend_before, *args, &proc)
108
108
  end
109
109
 
110
110
  # Appends a global <tt>before</tt> block to all example groups.
@@ -119,40 +119,40 @@ module Spec
119
119
  # config.prepend_before(:type => :farm)
120
120
  #
121
121
  def append_before(*args, &proc)
122
- scope, options = scope_and_options(*args)
123
- example_group = ExampleGroupFactory.get(
124
- get_type_from_options(options)
125
- )
126
- example_group.append_before(scope, &proc)
122
+ add_callback(:append_before, *args, &proc)
127
123
  end
128
124
  alias_method :before, :append_before
129
125
 
130
126
  # Prepends a global <tt>after</tt> block to all example groups.
131
127
  # See #append_before for filtering semantics.
132
128
  def prepend_after(*args, &proc)
133
- scope, options = scope_and_options(*args)
134
- example_group = ExampleGroupFactory.get(
135
- get_type_from_options(options)
136
- )
137
- example_group.prepend_after(scope, &proc)
129
+ add_callback(:prepend_after, *args, &proc)
138
130
  end
139
131
  alias_method :after, :prepend_after
140
132
 
141
133
  # Appends a global <tt>after</tt> block to all example groups.
142
134
  # See #append_before for filtering semantics.
143
135
  def append_after(*args, &proc)
144
- scope, options = scope_and_options(*args)
145
- example_group = ExampleGroupFactory.get(
146
- get_type_from_options(options)
147
- )
148
- example_group.append_after(scope, &proc)
136
+ add_callback(:append_after, *args, &proc)
149
137
  end
150
138
 
151
139
  private
140
+
141
+ def include_or_extend(*args)
142
+ action = args.shift
143
+ args << {} unless Hash === args.last
144
+ modules, options = Spec::Example.args_and_options(*args)
145
+ required_example_group = get_type_from_options(options)
146
+ required_example_group = required_example_group.to_sym if required_example_group
147
+ modules.each do |mod|
148
+ ExampleGroupFactory.get(required_example_group).send(action, mod)
149
+ end
150
+ end
152
151
 
153
- def scope_and_options(*args)
154
- args, options = args_and_options(*args)
155
- scope = (args[0] || :each), options
152
+ def add_callback(sym, *args, &proc)
153
+ scope, options = Spec::Example.scope_and_options(*args)
154
+ example_group = ExampleGroupFactory.get(get_type_from_options(options))
155
+ example_group.__send__(sym, scope, &proc)
156
156
  end
157
157
 
158
158
  def get_type_from_options(options)
@@ -7,9 +7,11 @@ module Spec
7
7
  default(ExampleGroup)
8
8
  end
9
9
 
10
- def all_registered?(example_group_classes)
10
+ def registered_or_ancestor_of_registered?(example_group_classes) # :nodoc:
11
11
  example_group_classes.each do |example_group_class|
12
- return false unless registered_or_ancestor_of_registered? example_group_class
12
+ return false unless registered_types.any? do |registered_type|
13
+ registered_type.ancestors.include? example_group_class
14
+ end
13
15
  end
14
16
  return true
15
17
  end
@@ -48,11 +50,14 @@ module Spec
48
50
  end
49
51
 
50
52
  def create_example_group(*args, &block)
51
- opts = Hash === args.last ? args.last : {}
52
- superclass = determine_superclass(opts)
53
+ raise ArgumentError if args.empty?
54
+ raise ArgumentError unless block
55
+ args << {} unless Hash === args.last
56
+ args.last[:spec_path] ||= File.expand_path(caller(0)[2])
57
+ superclass = determine_superclass(args.last)
53
58
  superclass.describe(*args, &block)
54
59
  end
55
-
60
+
56
61
  protected
57
62
 
58
63
  def determine_superclass(opts)
@@ -66,10 +71,6 @@ module Spec
66
71
 
67
72
  private
68
73
 
69
- def registered_or_ancestor_of_registered? example_group_class
70
- registered_types.any? {|registered_type| registered_type.ancestors.include? example_group_class}
71
- end
72
-
73
74
  def registered_types
74
75
  @example_group_types.values
75
76
  end