rspec 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. data/{CHANGES → History.txt} +116 -64
  2. data/Manifest.txt +403 -0
  3. data/{MIT-LICENSE → README.txt} +43 -0
  4. data/Rakefile +39 -212
  5. data/{TODO → TODO.txt} +0 -0
  6. data/bin/autospec +4 -0
  7. data/bin/spec +1 -1
  8. data/examples/pure/yielding_example.rb +33 -0
  9. data/examples/stories/game-of-life/.loadpath +5 -0
  10. data/examples/stories/game-of-life/behaviour/everything.rb +1 -1
  11. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +17 -17
  12. data/init.rb +9 -0
  13. data/lib/autotest/discover.rb +1 -1
  14. data/lib/autotest/rspec.rb +3 -29
  15. data/lib/spec.rb +10 -12
  16. data/lib/spec/adapters.rb +1 -0
  17. data/lib/spec/adapters/ruby_engine.rb +26 -0
  18. data/lib/spec/adapters/ruby_engine/mri.rb +8 -0
  19. data/lib/spec/adapters/ruby_engine/rubinius.rb +8 -0
  20. data/lib/spec/example/errors.rb +6 -0
  21. data/lib/spec/example/example_group_methods.rb +17 -14
  22. data/lib/spec/example/example_matcher.rb +2 -0
  23. data/lib/spec/example/example_methods.rb +4 -9
  24. data/lib/spec/example/module_inclusion_warnings.rb +2 -1
  25. data/lib/spec/expectations/extensions/object.rb +2 -2
  26. data/lib/spec/expectations/handler.rb +8 -16
  27. data/lib/spec/extensions/main.rb +2 -17
  28. data/lib/spec/matchers.rb +8 -2
  29. data/lib/spec/matchers/be.rb +0 -3
  30. data/lib/spec/matchers/change.rb +44 -40
  31. data/lib/spec/matchers/has.rb +1 -1
  32. data/lib/spec/matchers/have.rb +17 -12
  33. data/lib/spec/matchers/operator_matcher.rb +10 -4
  34. data/lib/spec/matchers/simple_matcher.rb +113 -10
  35. data/lib/spec/mocks.rb +1 -1
  36. data/lib/spec/mocks/argument_constraints.rb +185 -0
  37. data/lib/spec/mocks/argument_expectation.rb +35 -173
  38. data/lib/spec/mocks/framework.rb +1 -1
  39. data/lib/spec/mocks/message_expectation.rb +30 -5
  40. data/lib/spec/mocks/methods.rb +14 -2
  41. data/lib/spec/mocks/mock.rb +4 -0
  42. data/lib/spec/mocks/proxy.rb +46 -5
  43. data/lib/spec/mocks/spec_methods.rb +9 -1
  44. data/lib/spec/rake/spectask.rb +14 -22
  45. data/lib/spec/rake/verify_rcov.rb +3 -3
  46. data/lib/spec/runner.rb +18 -6
  47. data/lib/spec/runner/backtrace_tweaker.rb +6 -7
  48. data/lib/spec/runner/command_line.rb +6 -17
  49. data/lib/spec/runner/drb_command_line.rb +1 -1
  50. data/lib/spec/runner/formatter/base_formatter.rb +3 -1
  51. data/lib/spec/runner/formatter/base_text_formatter.rb +5 -9
  52. data/lib/spec/runner/formatter/html_formatter.rb +1 -1
  53. data/lib/spec/runner/formatter/nested_text_formatter.rb +1 -1
  54. data/lib/spec/runner/formatter/progress_bar_formatter.rb +2 -2
  55. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  56. data/lib/spec/runner/formatter/story/html_formatter.rb +62 -16
  57. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +68 -16
  58. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
  59. data/lib/spec/runner/heckle_runner.rb +2 -2
  60. data/lib/spec/runner/option_parser.rb +2 -1
  61. data/lib/spec/runner/options.rb +18 -9
  62. data/lib/spec/runner/reporter.rb +24 -4
  63. data/lib/spec/runner/spec_parser.rb +1 -1
  64. data/lib/spec/story/runner.rb +1 -2
  65. data/lib/spec/story/runner/story_mediator.rb +14 -0
  66. data/lib/spec/story/runner/story_parser.rb +20 -0
  67. data/lib/spec/story/step.rb +40 -28
  68. data/lib/spec/story/step_mother.rb +2 -1
  69. data/lib/spec/story/world.rb +6 -2
  70. data/lib/spec/version.rb +13 -22
  71. data/rake_tasks/failing_examples_with_html.rake +1 -1
  72. data/rake_tasks/verify_rcov.rake +2 -2
  73. data/rspec.gemspec +33 -0
  74. data/spec/autotest/rspec_spec.rb +90 -141
  75. data/spec/spec/adapters/ruby_engine_spec.rb +16 -0
  76. data/spec/spec/example/base_formatter_spec.rb +112 -0
  77. data/spec/spec/example/example_group_factory_spec.rb +2 -2
  78. data/spec/spec/example/example_group_methods_spec.rb +55 -4
  79. data/spec/spec/example/example_group_spec.rb +4 -3
  80. data/spec/spec/example/example_methods_spec.rb +18 -14
  81. data/spec/spec/example/pending_module_spec.rb +38 -0
  82. data/spec/spec/example/shared_example_group_spec.rb +1 -1
  83. data/spec/spec/expectations/extensions/object_spec.rb +0 -12
  84. data/spec/spec/extensions/main_spec.rb +3 -8
  85. data/spec/spec/matchers/change_spec.rb +16 -6
  86. data/spec/spec/matchers/handler_spec.rb +58 -37
  87. data/spec/spec/matchers/has_spec.rb +10 -0
  88. data/spec/spec/matchers/have_spec.rb +105 -2
  89. data/spec/spec/matchers/operator_matcher_spec.rb +35 -2
  90. data/spec/spec/matchers/simple_matcher_spec.rb +64 -2
  91. data/spec/spec/mocks/any_number_of_times_spec.rb +7 -0
  92. data/spec/spec/mocks/bug_report_496.rb +17 -0
  93. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +7 -1
  94. data/spec/spec/mocks/hash_including_matcher_spec.rb +45 -24
  95. data/spec/spec/mocks/mock_spec.rb +55 -10
  96. data/spec/spec/mocks/nil_expectation_warning_spec.rb +54 -0
  97. data/spec/spec/mocks/null_object_mock_spec.rb +14 -0
  98. data/spec/spec/mocks/options_hash_spec.rb +18 -28
  99. data/spec/spec/mocks/partial_mock_spec.rb +2 -0
  100. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +20 -6
  101. data/spec/spec/mocks/stub_spec.rb +7 -0
  102. data/spec/spec/runner/command_line_spec.rb +5 -12
  103. data/spec/spec/runner/drb_command_line_spec.rb +13 -6
  104. data/spec/spec/runner/formatter/html_formatter_spec.rb +2 -1
  105. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +3 -3
  106. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +20 -2
  107. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -1
  108. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +3 -3
  109. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +76 -2
  110. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +161 -0
  111. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
  112. data/spec/spec/runner/heckle_runner_spec.rb +8 -8
  113. data/spec/spec/runner/option_parser_spec.rb +21 -6
  114. data/spec/spec/runner/output_one_time_fixture_runner.rb +1 -1
  115. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -0
  116. data/spec/spec/runner/reporter_spec.rb +51 -5
  117. data/spec/spec/runner/spec_parser_spec.rb +4 -4
  118. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +2 -5
  119. data/spec/spec/story/runner/story_mediator_spec.rb +10 -0
  120. data/spec/spec/story/runner/story_parser_spec.rb +23 -6
  121. data/spec/spec/story/scenario_spec.rb +1 -3
  122. data/spec/spec/story/step_mother_spec.rb +12 -0
  123. data/spec/spec/story/step_spec.rb +57 -4
  124. data/spec/spec/story/story_spec.rb +1 -3
  125. data/spec/spec/story/world_spec.rb +1 -1
  126. data/spec/spec_helper.rb +21 -68
  127. data/stories/all.rb +1 -1
  128. data/stories/configuration/before_blocks.story +21 -0
  129. data/stories/configuration/stories.rb +7 -0
  130. data/stories/example_groups/stories.rb +3 -4
  131. data/stories/resources/spec/before_blocks_example.rb +32 -0
  132. data/stories/stories/multiline_steps.story +23 -0
  133. data/stories/stories/steps/multiline_steps.rb +13 -0
  134. data/stories/stories/stories.rb +6 -0
  135. data/story_server/prototype/javascripts/builder.js +136 -0
  136. data/story_server/prototype/javascripts/controls.js +972 -0
  137. data/story_server/prototype/javascripts/dragdrop.js +976 -0
  138. data/story_server/prototype/javascripts/effects.js +1117 -0
  139. data/story_server/prototype/javascripts/prototype.js +4140 -0
  140. data/story_server/prototype/javascripts/rspec.js +149 -0
  141. data/story_server/prototype/javascripts/scriptaculous.js +58 -0
  142. data/story_server/prototype/javascripts/slider.js +276 -0
  143. data/story_server/prototype/javascripts/sound.js +55 -0
  144. data/story_server/prototype/javascripts/unittest.js +568 -0
  145. data/story_server/prototype/lib/server.rb +24 -0
  146. data/story_server/prototype/stories.html +176 -0
  147. data/story_server/prototype/stylesheets/rspec.css +136 -0
  148. data/story_server/prototype/stylesheets/test.css +90 -0
  149. metadata +166 -166
  150. data/README +0 -36
  151. data/UPGRADE +0 -7
  152. data/bin/spec_translator +0 -8
  153. data/lib/spec/mocks/argument_constraint_matchers.rb +0 -31
  154. data/lib/spec/translator.rb +0 -114
  155. data/spec/spec/example/example_spec.rb +0 -53
  156. data/spec/spec/runner/execution_context_spec.rb +0 -37
  157. data/spec/spec/translator_spec.rb +0 -265
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/../../../../spec_helper'
2
+ require 'spec/runner/formatter/story/progress_bar_formatter'
3
+
4
+ module Spec
5
+ module Runner
6
+ module Formatter
7
+ module Story
8
+ describe ProgressBarFormatter do
9
+ before :each do
10
+ # given
11
+ @out = StringIO.new
12
+ @out.stub!(:tty?).and_return(true)
13
+ @tweaker = mock('tweaker')
14
+ @tweaker.stub!(:tweak_backtrace)
15
+ @options = mock('options')
16
+ @options.stub!(:colour).and_return(true)
17
+ @options.stub!(:backtrace_tweaker).and_return(@tweaker)
18
+
19
+ @formatter = ProgressBarFormatter.new(@options, @out)
20
+ end
21
+
22
+ it 'should print some white space before test summary' do
23
+ #when
24
+ @formatter.run_started(1)
25
+ @formatter.run_ended
26
+
27
+ #then
28
+ @out.string.should =~ /^\n{2}/
29
+ end
30
+
31
+ it "should print how long tests took to complete" do
32
+ #when
33
+ now = Time.now
34
+ future = now+1
35
+ Time.stub!(:now).and_return(now)
36
+ @formatter.run_started(1)
37
+ Time.stub!(:now).and_return(future)
38
+ @formatter.run_ended
39
+
40
+ #then
41
+ @out.string.should include("Finished in %f seconds" % (future-now))
42
+ end
43
+
44
+
45
+ it "should push green dot for passing scenario" do
46
+ #when
47
+ @formatter.scenario_started('','')
48
+ @formatter.step_succeeded('', '')
49
+ @formatter.scenario_ended
50
+ @formatter.story_ended '', ''
51
+
52
+ #then
53
+ @out.string.should eql("\e[32m.\e[0m")
54
+ end
55
+
56
+ it "should push red F for failure scenario" do
57
+ #when
58
+ @formatter.scenario_started('','')
59
+ @formatter.step_failed('', '')
60
+ @formatter.scenario_failed('', '', '')
61
+ @formatter.story_ended '', ''
62
+
63
+ #then
64
+ @out.string.should eql("\e[31mF\e[0m")
65
+ end
66
+
67
+ it "should push yellow P for pending scenario" do
68
+ #when
69
+ @formatter.scenario_started('','')
70
+ @formatter.step_pending('', '')
71
+ @formatter.scenario_pending('story', '', '')
72
+ @formatter.story_ended '', ''
73
+
74
+ #then
75
+ @out.string.should eql("\e[33mP\e[0m")
76
+ end
77
+
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -21,18 +21,18 @@ unless [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM}
21
21
  end
22
22
 
23
23
  it "should heckle all methods in all classes in a module" do
24
- @heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
25
- @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
26
- @heckle_class.should_receive(:new).with("Foo::Zap", "three", rspec_options).and_return(@heckle)
27
- @heckle_class.should_receive(:new).with("Foo::Zap", "four", rspec_options).and_return(@heckle)
24
+ @heckle_class.should_receive(:new).with("Foo::Bar", "one", Spec::Runner.options).and_return(@heckle)
25
+ @heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
26
+ @heckle_class.should_receive(:new).with("Foo::Zap", "three", Spec::Runner.options).and_return(@heckle)
27
+ @heckle_class.should_receive(:new).with("Foo::Zap", "four", Spec::Runner.options).and_return(@heckle)
28
28
 
29
29
  heckle_runner = Spec::Runner::HeckleRunner.new("Foo", @heckle_class)
30
30
  heckle_runner.heckle_with
31
31
  end
32
32
 
33
33
  it "should heckle all methods in a class" do
34
- @heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
35
- @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
34
+ @heckle_class.should_receive(:new).with("Foo::Bar", "one", Spec::Runner.options).and_return(@heckle)
35
+ @heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
36
36
 
37
37
  heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar", @heckle_class)
38
38
  heckle_runner.heckle_with
@@ -46,14 +46,14 @@ unless [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM}
46
46
  end
47
47
 
48
48
  it "should heckle specific method in a class (with #)" do
49
- @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
49
+ @heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
50
50
 
51
51
  heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar#two", @heckle_class)
52
52
  heckle_runner.heckle_with
53
53
  end
54
54
 
55
55
  it "should heckle specific method in a class (with .)" do
56
- @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
56
+ @heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec::Runner.options).and_return(@heckle)
57
57
 
58
58
  heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar.two", @heckle_class)
59
59
  heckle_runner.heckle_with
@@ -1,6 +1,21 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
  require 'fileutils'
3
3
 
4
+ module Custom
5
+ class ExampleGroupRunner
6
+ attr_reader :options, :arg
7
+ def initialize(options, arg)
8
+ @options, @arg = options, arg
9
+ end
10
+
11
+ def load_files(files)
12
+ end
13
+
14
+ def run
15
+ end
16
+ end
17
+ end
18
+
4
19
  describe "OptionParser" do
5
20
  before(:each) do
6
21
  @out = StringIO.new
@@ -76,7 +91,7 @@ describe "OptionParser" do
76
91
  it "should print version to stdout" do
77
92
  options = parse(["--version"])
78
93
  @out.rewind
79
- @out.read.should match(/RSpec-\d+\.\d+\.\d+.*\(build \d+\) - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n)
94
+ @out.read.should match(/rspec version \d+\.\d+\.\d+/n)
80
95
  end
81
96
 
82
97
  it "should require file when require specified" do
@@ -231,19 +246,19 @@ describe "OptionParser" do
231
246
 
232
247
  describe "when attempting a focussed spec" do
233
248
  attr_reader :file, :dir
234
- before do
235
- @original_rspec_options = $rspec_options
249
+ before(:each) do
250
+ @original_rspec_options = Spec::Runner.options
236
251
  @file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
237
252
  @dir = File.dirname(file)
238
253
  end
239
254
 
240
- after do
241
- $rspec_options = @original_rspec_options
255
+ after(:each) do
256
+ Spec::Runner.use @original_rspec_options
242
257
  end
243
258
 
244
259
  def parse(args)
245
260
  options = super
246
- $rspec_options = options
261
+ Spec::Runner.use options
247
262
  options.filename_pattern = "*_fixture.rb"
248
263
  options
249
264
  end
@@ -1,7 +1,7 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  require "#{dir}/../../spec_helper"
3
3
 
4
- triggering_double_output = rspec_options
4
+ triggering_double_output = Spec::Runner.options
5
5
  options = Spec::Runner::OptionParser.parse(
6
6
  ["#{dir}/output_one_time_fixture.rb"], $stderr, $stdout
7
7
  )
@@ -51,6 +51,12 @@ module Spec
51
51
  @tweaker.tweak_backtrace(@error)
52
52
  @error.backtrace.should include("/a/b/c/d.rb")
53
53
  end
54
+
55
+ it "should gracefully handle backtraces with newlines" do
56
+ @error.set_backtrace(["we like\nbin/spec:\nnewlines"])
57
+ @tweaker.tweak_backtrace(@error)
58
+ @error.backtrace.should include("we like\nnewlines")
59
+ end
54
60
  end
55
61
  end
56
62
  end
@@ -17,7 +17,7 @@ module Spec
17
17
  end
18
18
 
19
19
  def failure
20
- Mocks::DuckTypeArgConstraint.new(:header, :exception)
20
+ Mocks::ArgumentConstraints::DuckTypeArgConstraint.new(:header, :exception)
21
21
  end
22
22
 
23
23
  def create_example_group(description_text)
@@ -155,26 +155,72 @@ module Spec
155
155
  end
156
156
 
157
157
  describe Reporter, "reporting one pending example (ExamplePendingError)" do
158
+ before :each do
159
+ @pending_error = Spec::Example::ExamplePendingError.new("reason")
160
+ @pending_caller = @pending_error.pending_caller
161
+ end
162
+
158
163
  it "should tell formatter example is pending" do
159
164
  example = ExampleGroup.new("example")
160
- formatter.should_receive(:example_pending).with(example, "reason")
165
+ formatter.should_receive(:example_pending).with(example, "reason", @pending_caller)
161
166
  formatter.should_receive(:add_example_group).with(example_group)
162
167
  reporter.add_example_group(example_group)
163
- reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
168
+ reporter.example_finished(example, @pending_error)
164
169
  end
165
170
 
166
171
  it "should account for pending example in stats" do
167
172
  example = ExampleGroup.new("example")
168
- formatter.should_receive(:example_pending).with(example, "reason")
173
+ formatter.should_receive(:example_pending).with(example, "reason", @pending_caller)
169
174
  formatter.should_receive(:start_dump)
170
175
  formatter.should_receive(:dump_pending)
171
176
  formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
172
177
  formatter.should_receive(:close).with(no_args)
173
178
  formatter.should_receive(:add_example_group).with(example_group)
174
179
  reporter.add_example_group(example_group)
175
- reporter.example_finished(example, Spec::Example::ExamplePendingError.new("reason"))
180
+ reporter.example_finished(example, @pending_error)
176
181
  reporter.dump
177
182
  end
183
+
184
+ describe "to formatters which have example_pending's arity of 2 (which is now deprecated)" do
185
+ before :each do
186
+ Kernel.stub!(:warn).with(Spec::Runner::Reporter::EXAMPLE_PENDING_DEPRECATION_WARNING)
187
+
188
+ @deprecated_formatter = Class.new(@formatter.class) do
189
+ attr_reader :example_passed_to_method, :message_passed_to_method
190
+
191
+ def example_pending(example_passed_to_method, message_passed_to_method)
192
+ @example_passed_to_method = example_passed_to_method
193
+ @message_passed_to_method = message_passed_to_method
194
+ end
195
+ end.new(options, formatter_output)
196
+
197
+ options.formatters << @deprecated_formatter
198
+ end
199
+
200
+ it "should pass the correct example to the formatter" do
201
+ example = ExampleGroup.new("example")
202
+ reporter.add_example_group(example_group)
203
+ reporter.example_finished(example, @pending_error)
204
+
205
+ @deprecated_formatter.example_passed_to_method.should == example
206
+ end
207
+
208
+ it "should pass the correct pending error message to the formatter" do
209
+ example = ExampleGroup.new("example")
210
+ reporter.add_example_group(example_group)
211
+ reporter.example_finished(example, @pending_error)
212
+
213
+ @deprecated_formatter.message_passed_to_method.should == @pending_error.message
214
+ end
215
+
216
+ it "should raise a deprecation warning" do
217
+ Kernel.should_receive(:warn).with(Spec::Runner::Reporter::EXAMPLE_PENDING_DEPRECATION_WARNING)
218
+
219
+ example = ExampleGroup.new("example")
220
+ reporter.add_example_group(example_group)
221
+ reporter.example_finished(example, @pending_error)
222
+ end
223
+ end
178
224
  end
179
225
 
180
226
  describe Reporter, "reporting one pending example (PendingExampleFixedError)" do
@@ -3,15 +3,15 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  describe "SpecParser" do
4
4
  attr_reader :parser, :file
5
5
  before(:each) do
6
- @original_rspec_options = $rspec_options
7
- $rspec_options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
6
+ @original_rspec_options = Spec::Runner.options
7
+ Spec::Runner.use ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
8
8
  @parser = Spec::Runner::SpecParser.new
9
9
  @file = "#{File.dirname(__FILE__)}/spec_parser/spec_parser_fixture.rb"
10
10
  load file
11
11
  end
12
12
 
13
- after do
14
- $rspec_options = @original_rspec_options
13
+ after(:each) do
14
+ Spec::Runner.use @original_rspec_options
15
15
  end
16
16
 
17
17
  it "should find spec name for 'specify' at same line" do
@@ -22,11 +22,8 @@ module Spec
22
22
 
23
23
  it "should parse a story file" do
24
24
  runner = PlainTextStoryRunner.new("path")
25
- during {
26
- runner.run(mock('runner'))
27
- }.expect {
28
- @parser.should_receive(:parse).with(["this", "and that"])
29
- }
25
+ @parser.should_receive(:parse).with(["this", "and that"])
26
+ runner.run(mock('runner'))
30
27
  end
31
28
 
32
29
  it "should build up a mediator with its own steps and the singleton story_runner" do
@@ -126,6 +126,16 @@ module Spec
126
126
  @runner.stories.first[:foo].should == :bar
127
127
  end
128
128
 
129
+ it "should description" do
130
+ @mediator = StoryMediator.new @step_group, @runner, :foo => :bar
131
+ @mediator.create_story "title", "narrative"
132
+ @mediator.create_scenario "scenario"
133
+ @mediator.create_given "something"
134
+ given = @mediator.last_step
135
+ @mediator.add_to_last " else"
136
+ given.name.should == "something else"
137
+ end
138
+
129
139
  end
130
140
 
131
141
  end
@@ -244,9 +244,15 @@ module Spec
244
244
  @parser.parse(["Story: s", "Scenario: s", "Given first", "Then: and there"])
245
245
  end
246
246
 
247
- it "should ignore other" do
248
- @parser.parse(["Story: s", "Scenario: s", "Given first", "this is ignored"])
247
+ it "should ignore lines beginning with '#'" do
248
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "#this is ignored"])
249
+ end
250
+
251
+ it "should not ignore lines beginning with non-keywords" do
252
+ @story_mediator.should_receive(:add_to_last).with("\nthis is not ignored")
253
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "this is not ignored"])
249
254
  end
255
+
250
256
  end
251
257
 
252
258
  describe StoryParser, "in When state" do
@@ -309,8 +315,13 @@ module Spec
309
315
  @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: and there"])
310
316
  end
311
317
 
312
- it "should ignore other" do
313
- @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "this is ignored"])
318
+ it "should ignore lines beginning with '#'" do
319
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "#this is ignored"])
320
+ end
321
+
322
+ it "should not ignore lines beginning with non-keywords" do
323
+ @story_mediator.should_receive(:add_to_last).with("\nthis is not ignored")
324
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When else", "this is not ignored"])
314
325
  end
315
326
  end
316
327
 
@@ -375,8 +386,14 @@ module Spec
375
386
  @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "And: ever"])
376
387
  end
377
388
 
378
- it "should ignore other" do
379
- @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "this is ignored"])
389
+
390
+ it "should ignore lines beginning with '#'" do
391
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "#this is ignored"])
392
+ end
393
+
394
+ it "should not ignore lines beginning with non-keywords" do
395
+ @story_mediator.should_receive(:add_to_last).with("\nthis is not ignored")
396
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When else", "Then what", "this is not ignored"])
380
397
  end
381
398
  end
382
399
  end
@@ -8,9 +8,7 @@ module Spec
8
8
  story = StoryBuilder.new.to_story
9
9
 
10
10
  # when
11
- error = exception_from do
12
- Scenario.new story, 'name'
13
- end
11
+ error = exception_from { Scenario.new story, 'name' }
14
12
 
15
13
  # then
16
14
  error.should be_nil
@@ -42,6 +42,18 @@ module Spec
42
42
  end.should raise_error(Spec::Example::ExamplePendingError, /Unimplemented/)
43
43
  end
44
44
 
45
+ it "should create a default step with it's name stripped" do
46
+ # given
47
+ step_mother = StepMother.new
48
+
49
+ # when
50
+ step = step_mother.find(:given, "doesn't exist\n\n")
51
+
52
+ # then
53
+ step.should be_an_instance_of(Step)
54
+ step.name.should == "doesn't exist"
55
+ end
56
+
45
57
  it 'should clear itself' do
46
58
  # given
47
59
  step_mother = StepMother.new
@@ -2,12 +2,17 @@ require File.dirname(__FILE__) + '/story_helper'
2
2
 
3
3
  module Spec
4
4
  module Story
5
- describe Step, "matching" do
5
+ describe Step, "#matching" do
6
6
  it "should match a text string" do
7
7
  step = Step.new("this text") {}
8
8
  step.matches?("this text").should be_true
9
9
  end
10
10
 
11
+ it "should match a text string that has additional line returns" do
12
+ step = Step.new("this text") {}
13
+ step.matches?("this text\n\n").should be_true
14
+ end
15
+
11
16
  it "should not match a text string that does not start the same" do
12
17
  step = Step.new("this text") {}
13
18
  step.matches?("Xthis text").should be_false
@@ -32,6 +37,11 @@ module Spec
32
37
  step = Step.new("1 $one 2 $two 3 $three 4") {}
33
38
  step.matches?("1 a 2 b 3 c 4").should be_true
34
39
  end
40
+
41
+ it "should match a text string with two params sharing a prefix" do
42
+ step = Step.new("I am cool $n times out of $n_total")
43
+ step.matches?("I am cool 3 times out of 7").should be_true
44
+ end
35
45
 
36
46
  it "should match a text string with a param at the beginning" do
37
47
  step = Step.new("$one 2 3") {}
@@ -88,6 +98,11 @@ module Spec
88
98
  step.matches?("before () after").should be_true
89
99
  end
90
100
 
101
+ it "should not get bogged down by regular expression special characters in strings" do
102
+ step = Step.new("These characters should work ? ( ) [ ] { } ^ !") {}
103
+ step.matches?("These characters should work ? ( ) [ ] { } ^ !").should be_true
104
+ end
105
+
91
106
  it "should match any option of an alteration" do
92
107
  step = Step.new(/(he|she) is cool/) {}
93
108
  step.matches?("he is cool").should be_true
@@ -121,13 +136,51 @@ module Spec
121
136
  step = Step.new(/show me the \$$money/) {}
122
137
  step.matches?("show me the $123").should be_true
123
138
  end
139
+
140
+ it "should match a multiline regex" do
141
+ step = Step.new(/.*should have text.$text/) {}
142
+ step.matches?(<<TEXT).should be_true
143
+ should have text
144
+ this is the text
145
+ and so is this
146
+ TEXT
147
+ end
148
+
149
+ it "should match the beginning of the string, not the line" do
150
+ step = Step.new(/should have text/) {}
151
+ step.matches?(<<TEXT).should be_false
152
+ whatever
153
+ should have text
154
+ TEXT
155
+ end
156
+
157
+ it "should match the end of the string, not the line" do
158
+ step = Step.new(/should have text/) {}
159
+ step.matches?(<<TEXT).should be_false
160
+ should have text
161
+ whatever
162
+ TEXT
163
+ end
164
+ end
165
+
166
+ describe Step, "#parse_args" do
167
+ it "should return an empty array for a text string with no parameters" do
168
+ step = Step.new("this text") {}
169
+ step.parse_args("this text").should == []
170
+ end
171
+
172
+ it "should return an empty array for a text string with additional line returns and no parameters" do
173
+ step = Step.new("this text") {}
174
+ step.parse_args("this text\n\n").should == []
175
+ end
124
176
  end
125
177
 
126
178
  describe Step do
127
- it "should make complain with no block" do
179
+ it "should be pending with no block" do
180
+ step = Step.new("foo")
128
181
  lambda {
129
- step = Step.new("foo")
130
- }.should raise_error
182
+ step.perform(Object.new)
183
+ }.should raise_error(Spec::Example::ExamplePendingError, "Not Yet Implemented")
131
184
  end
132
185
 
133
186
  it "should perform itself on an object" do