rspec-core 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +8 -3
- data/Guardfile +5 -0
- data/History.markdown +32 -2
- data/README.markdown +10 -3
- data/Rakefile +12 -13
- data/Upgrade.markdown +175 -121
- data/bin/autospec +13 -0
- data/bin/rspec +24 -1
- data/features/command_line/line_number_appended_to_path.feature +3 -1
- data/features/command_line/line_number_option.feature +3 -1
- data/features/command_line/tag.feature +74 -0
- data/features/filtering/exclusion_filters.feature +1 -1
- data/features/filtering/implicit_filters.feature +166 -0
- data/features/hooks/around_hooks.feature +51 -44
- data/features/metadata/described_class.feature +3 -0
- data/features/pending/pending_examples.feature +76 -0
- data/features/step_definitions/additional_cli_steps.rb +11 -0
- data/features/subject/attribute_of_subject.feature +8 -0
- data/features/subject/explicit_subject.feature +8 -13
- data/features/subject/implicit_receiver.feature +29 -0
- data/features/subject/implicit_subject.feature +6 -7
- data/lib/rspec/core.rb +3 -21
- data/lib/rspec/core/backward_compatibility.rb +22 -3
- data/lib/rspec/core/command_line.rb +1 -0
- data/lib/rspec/core/configuration.rb +34 -6
- data/lib/rspec/core/configuration_options.rb +1 -3
- data/lib/rspec/core/example.rb +0 -5
- data/lib/rspec/core/example_group.rb +9 -8
- data/lib/rspec/core/expecting/with_rspec.rb +11 -0
- data/lib/rspec/core/extensions/object.rb +1 -1
- data/lib/rspec/core/formatters/base_formatter.rb +1 -6
- data/lib/rspec/core/hooks.rb +1 -1
- data/lib/rspec/core/metadata.rb +15 -5
- data/lib/rspec/core/option_parser.rb +17 -0
- data/lib/rspec/core/pending.rb +10 -1
- data/lib/rspec/core/rake_task.rb +32 -10
- data/lib/rspec/core/reporter.rb +1 -0
- data/lib/rspec/core/subject.rb +58 -59
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +9 -4
- data/rspec-core.gemspec +4 -11
- data/spec/rspec/core/command_line_spec.rb +16 -5
- data/spec/rspec/core/configuration_options_spec.rb +6 -0
- data/spec/rspec/core/configuration_spec.rb +89 -6
- data/spec/rspec/core/deprecations_spec.rb +17 -1
- data/spec/rspec/core/example_group_spec.rb +29 -14
- data/spec/rspec/core/example_spec.rb +0 -7
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +49 -33
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +46 -26
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +49 -33
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +19 -19
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +56 -33
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +26 -38
- data/spec/rspec/core/metadata_spec.rb +153 -132
- data/spec/rspec/core/pending_example_spec.rb +133 -25
- data/spec/rspec/core/rake_task_spec.rb +25 -32
- data/spec/rspec/core/subject_spec.rb +15 -0
- data/spec/rspec/core/world_spec.rb +72 -61
- data/spec/spec_helper.rb +0 -14
- metadata +25 -135
- data/features/hooks/halt.feature +0 -26
@@ -212,22 +212,18 @@ a {
|
|
212
212
|
<span class="failed_spec_name">fails</span>
|
213
213
|
<div class="failure" id="failure_0">
|
214
214
|
<div class="message"><pre>RSpec::Core::PendingExampleFixedError</pre></div>
|
215
|
-
<div class="backtrace"><pre><a href="txmt://open?url=file:///Users/
|
216
|
-
<a href="txmt://open?url=file:///Users/
|
217
|
-
<a href="txmt://open?url=file:///Users/
|
218
|
-
<a href="txmt://open?url=file:///Users/
|
219
|
-
<a href="txmt://open?url=file:///Users/
|
220
|
-
<a href="txmt://open?url=file:///Users/
|
221
|
-
<a href="txmt://open?url=file:///Users/
|
222
|
-
<
|
223
|
-
<
|
224
|
-
<
|
225
|
-
<
|
226
|
-
|
227
|
-
<span class="linenum">12</span> <span class="keyword">end</span>
|
228
|
-
<span class="offending"><span class="linenum">13</span> <span class="keyword">raise</span> <span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Core</span><span class="punct">::</span><span class="constant">PendingExampleFixedError</span><span class="punct">.</span><span class="ident">new</span> <span class="keyword">if</span> <span class="ident">result</span></span>
|
229
|
-
<span class="linenum">14</span> <span class="keyword">end</span>
|
230
|
-
<span class="linenum">15</span> <span class="ident">throw</span> <span class="symbol">:pending_declared_in_example</span><span class="punct">,</span> <span class="ident">message</span></code></pre>
|
215
|
+
<div class="backtrace"><pre><a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=18">./spec/rspec/core/resources/formatter_specs.rb:18</a> :in `block (3 levels) in <top (required)>'
|
216
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=24">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:24</a> :in `block (2 levels) in <module:Formatters>'
|
217
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (5 levels) in <module:Formatters>'
|
218
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `open'
|
219
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in <module:Formatters>'
|
220
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
|
221
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in <module:Formatters>'</pre></div>
|
222
|
+
<pre class="ruby"><code><span class="linenum">20</span> <span class="keyword">rescue</span> <span class="constant">Exception</span> <span class="punct">=></span> <span class="ident">e</span>
|
223
|
+
<span class="linenum">21</span> <span class="keyword">end</span>
|
224
|
+
<span class="offending"><span class="linenum">22</span> <span class="keyword">raise</span> <span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Core</span><span class="punct">::</span><span class="constant">PendingExampleFixedError</span><span class="punct">.</span><span class="ident">new</span> <span class="keyword">if</span> <span class="ident">result</span></span>
|
225
|
+
<span class="linenum">23</span> <span class="keyword">end</span>
|
226
|
+
<span class="linenum">24</span> <span class="ident">throw</span> <span class="symbol">:pending_declared_in_example</span><span class="punct">,</span> <span class="ident">message</span></code></pre>
|
231
227
|
</div>
|
232
228
|
</dd>
|
233
229
|
</dl>
|
@@ -253,17 +249,13 @@ expected 2
|
|
253
249
|
|
254
250
|
(compared using ==)
|
255
251
|
</pre></div>
|
256
|
-
<div class="backtrace"><pre><a href="txmt://open?url=file:///Users/
|
257
|
-
<a href="txmt://open?url=file:///Users/
|
258
|
-
<a href="txmt://open?url=file:///Users/
|
259
|
-
<a href="txmt://open?url=file:///Users/
|
260
|
-
<a href="txmt://open?url=file:///Users/
|
261
|
-
<a href="txmt://open?url=file:///Users/
|
262
|
-
<a href="txmt://open?url=file:///Users/
|
263
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=71">./spec/spec_helper.rb:71</a> :in `block (3 levels) in <top (required)>'
|
264
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=45">./spec/spec_helper.rb:45</a> :in `instance_eval'
|
265
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=45">./spec/spec_helper.rb:45</a> :in `sandboxed'
|
266
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=71">./spec/spec_helper.rb:71</a> :in `block (2 levels) in <top (required)>'</pre></div>
|
252
|
+
<div class="backtrace"><pre><a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=33">./spec/rspec/core/resources/formatter_specs.rb:33</a> :in `block (2 levels) in <top (required)>'
|
253
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=24">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:24</a> :in `block (2 levels) in <module:Formatters>'
|
254
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (5 levels) in <module:Formatters>'
|
255
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `open'
|
256
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in <module:Formatters>'
|
257
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
|
258
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in <module:Formatters>'</pre></div>
|
267
259
|
<pre class="ruby"><code><span class="linenum">27</span> <span class="keyword">end</span>
|
268
260
|
<span class="linenum">28</span>
|
269
261
|
<span class="offending"><span class="linenum">29</span> <span class="keyword">raise</span><span class="punct">(</span><span class="constant">RSpec</span><span class="punct">::</span><span class="constant">Expectations</span><span class="punct">::</span><span class="constant">ExpectationNotMetError</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">message</span><span class="punct">))</span></span>
|
@@ -282,17 +274,13 @@ expected 2
|
|
282
274
|
<div class="failure" id="failure_0">
|
283
275
|
<div class="message"><pre>foo</pre></div>
|
284
276
|
<div class="backtrace"><pre>(erb):1:in `<main>'
|
285
|
-
<a href="txmt://open?url=file:///Users/
|
286
|
-
<a href="txmt://open?url=file:///Users/
|
287
|
-
<a href="txmt://open?url=file:///Users/
|
288
|
-
<a href="txmt://open?url=file:///Users/
|
289
|
-
<a href="txmt://open?url=file:///Users/
|
290
|
-
<a href="txmt://open?url=file:///Users/
|
291
|
-
<a href="txmt://open?url=file:///Users/
|
292
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=71">./spec/spec_helper.rb:71</a> :in `block (3 levels) in <top (required)>'
|
293
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=45">./spec/spec_helper.rb:45</a> :in `instance_eval'
|
294
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=45">./spec/spec_helper.rb:45</a> :in `sandboxed'
|
295
|
-
<a href="txmt://open?url=file:///Users/alex/code/ruby/rspec-core/spec/spec_helper.rb&line=71">./spec/spec_helper.rb:71</a> :in `block (2 levels) in <top (required)>'</pre></div>
|
277
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb&line=41">./spec/rspec/core/resources/formatter_specs.rb:41</a> :in `block (2 levels) in <top (required)>'
|
278
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=24">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:24</a> :in `block (2 levels) in <module:Formatters>'
|
279
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (5 levels) in <module:Formatters>'
|
280
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `open'
|
281
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=47">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:47</a> :in `block (4 levels) in <module:Formatters>'
|
282
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `chdir'
|
283
|
+
<a href="txmt://open?url=file:///Users/mmarston/code/rspec-dev/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb&line=46">./spec/rspec/core/formatters/text_mate_formatter_spec.rb:46</a> :in `block (3 levels) in <module:Formatters>'</pre></div>
|
296
284
|
<pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for (erb)</span></code></pre>
|
297
285
|
</div>
|
298
286
|
</dd>
|
@@ -4,7 +4,7 @@ module RSpec
|
|
4
4
|
module Core
|
5
5
|
describe Metadata do
|
6
6
|
|
7
|
-
describe "process" do
|
7
|
+
describe "#process" do
|
8
8
|
Metadata::RESERVED_KEYS.each do |key|
|
9
9
|
it "prohibits :#{key} as a hash key" do
|
10
10
|
m = Metadata.new
|
@@ -13,19 +13,121 @@ module RSpec
|
|
13
13
|
end.to raise_error(/:#{key} is not allowed/)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
18
|
-
|
19
|
-
it "just has the example description" do
|
17
|
+
it "uses :caller if passed as part of the user metadata" do
|
20
18
|
m = Metadata.new
|
21
|
-
m.process('group')
|
19
|
+
m.process('group', :caller => ['example_file:42'])
|
20
|
+
m[:example_group][:location].should == 'example_file:42'
|
21
|
+
end
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
describe "#apply_condition" do
|
25
|
+
|
26
|
+
let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
27
|
+
let(:parent_group_line_number) { parent_group_metadata[:example_group][:line_number] }
|
28
|
+
let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
29
|
+
let(:group_line_number) { group_metadata[:example_group][:line_number] }
|
30
|
+
let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"], :if => true) }
|
31
|
+
let(:example_line_number) { example_metadata[:line_number] }
|
32
|
+
let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) }
|
33
|
+
let(:world) { World.new }
|
34
|
+
|
35
|
+
before { RSpec.stub(:world) { world } }
|
36
|
+
|
37
|
+
it "matches the group when the line_number is the example group line number" do
|
38
|
+
world.should_receive(:preceding_declaration_line).and_return(group_line_number)
|
39
|
+
# this call doesn't really make sense since apply_condition is only called
|
40
|
+
# for example metadata not group metadata
|
41
|
+
group_metadata.apply_condition(:line_number, group_line_number).should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "matches the example when the line_number is the grandparent example group line number" do
|
45
|
+
world.should_receive(:preceding_declaration_line).and_return(parent_group_line_number)
|
46
|
+
example_metadata.apply_condition(:line_number, parent_group_line_number).should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "matches the example when the line_number is the parent example group line number" do
|
50
|
+
world.should_receive(:preceding_declaration_line).and_return(group_line_number)
|
51
|
+
example_metadata.apply_condition(:line_number, group_line_number).should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "matches the example when the line_number is the example line number" do
|
55
|
+
world.should_receive(:preceding_declaration_line).and_return(example_line_number)
|
56
|
+
example_metadata.apply_condition(:line_number, example_line_number).should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "matches when the line number is between this example and the next" do
|
60
|
+
world.should_receive(:preceding_declaration_line).and_return(example_line_number)
|
61
|
+
example_metadata.apply_condition(:line_number, example_line_number + 1).should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "does not match when the line number matches the next example" do
|
65
|
+
world.should_receive(:preceding_declaration_line).and_return(example_line_number + 2)
|
66
|
+
example_metadata.apply_condition(:line_number, example_line_number + 2).should be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
it "matches a proc that evaluates to true" do
|
70
|
+
example_metadata.apply_condition(:if, lambda { |v| v }).should be_true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not match a proc that evaluates to false" do
|
74
|
+
example_metadata.apply_condition(:if, lambda { |v| !v }).should be_false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "passes the metadata hash as the second argument if a given proc expects 2 args" do
|
78
|
+
passed_metadata = nil
|
79
|
+
example_metadata.apply_condition(:if, lambda { |v, m| passed_metadata = m })
|
80
|
+
passed_metadata.should == example_metadata
|
25
81
|
end
|
26
82
|
end
|
27
83
|
|
28
|
-
describe "
|
84
|
+
describe "#for_example" do
|
85
|
+
let(:metadata) { Metadata.new.process("group description") }
|
86
|
+
let(:mfe) { metadata.for_example("example description", {:arbitrary => :options}) }
|
87
|
+
let(:line_number) { __LINE__ - 1 }
|
88
|
+
|
89
|
+
it "stores the description" do
|
90
|
+
mfe[:description].should == "example description"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "stores the full_description (group description + example description)" do
|
94
|
+
mfe[:full_description].should == "group description example description"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "creates an empty execution result" do
|
98
|
+
mfe[:execution_result].should == {}
|
99
|
+
end
|
100
|
+
|
101
|
+
it "extracts file path from caller" do
|
102
|
+
mfe[:file_path].should == __FILE__
|
103
|
+
end
|
104
|
+
|
105
|
+
it "extracts line number from caller" do
|
106
|
+
mfe[:line_number].should == line_number
|
107
|
+
end
|
108
|
+
|
109
|
+
it "extracts location from caller" do
|
110
|
+
mfe[:location].should == "#{__FILE__}:#{line_number}"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "uses :caller if passed as an option" do
|
114
|
+
example_metadata = metadata.for_example('example description', {:caller => ['example_file:42']})
|
115
|
+
example_metadata[:location].should == 'example_file:42'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "merges arbitrary options" do
|
119
|
+
mfe[:arbitrary].should == :options
|
120
|
+
end
|
121
|
+
|
122
|
+
it "points :example_group to the same hash object" do
|
123
|
+
a = metadata.for_example("foo", {})[:example_group]
|
124
|
+
b = metadata.for_example("bar", {})[:example_group]
|
125
|
+
a[:description] = "new description"
|
126
|
+
b[:description].should == "new description"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe ":describes" do
|
29
131
|
context "with a String" do
|
30
132
|
it "returns nil" do
|
31
133
|
m = Metadata.new
|
@@ -57,37 +159,15 @@ module RSpec
|
|
57
159
|
end
|
58
160
|
end
|
59
161
|
|
60
|
-
describe "
|
61
|
-
it "
|
162
|
+
describe ":description" do
|
163
|
+
it "just has the example description" do
|
62
164
|
m = Metadata.new
|
63
165
|
m.process('group')
|
64
166
|
|
65
167
|
m = m.for_example("example", {})
|
66
|
-
m[:
|
67
|
-
end
|
68
|
-
|
69
|
-
%w[# . ::].each do |char|
|
70
|
-
context "with a 2nd arg starting with #{char}" do
|
71
|
-
it "removes the space" do
|
72
|
-
m = Metadata.new
|
73
|
-
m.process(Array, "#{char}method")
|
74
|
-
m[:example_group][:full_description].should eq("Array#{char}method")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "with a nested description starting with #" do
|
79
|
-
it "removes the space" do
|
80
|
-
m = Metadata.new
|
81
|
-
m.process("Object")
|
82
|
-
m = Metadata.new(m)
|
83
|
-
m.process("#{char}method")
|
84
|
-
m[:example_group][:full_description].should eq("Object#{char}method")
|
85
|
-
end
|
86
|
-
end
|
168
|
+
m[:description].should == "example"
|
87
169
|
end
|
88
|
-
end
|
89
170
|
|
90
|
-
describe "description" do
|
91
171
|
context "with a string" do
|
92
172
|
it "provides the submitted description" do
|
93
173
|
m = Metadata.new
|
@@ -116,8 +196,16 @@ module RSpec
|
|
116
196
|
end
|
117
197
|
end
|
118
198
|
|
119
|
-
describe "
|
120
|
-
it "concats
|
199
|
+
describe ":full_description" do
|
200
|
+
it "concats example group name and description" do
|
201
|
+
group_metadata = Metadata.new
|
202
|
+
group_metadata.process('group')
|
203
|
+
|
204
|
+
example_metadata = group_metadata.for_example("example", {})
|
205
|
+
example_metadata[:full_description].should == "group example"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "concats nested example group descriptions" do
|
121
209
|
parent = Metadata.new
|
122
210
|
parent.process(Object, 'parent')
|
123
211
|
|
@@ -126,32 +214,42 @@ module RSpec
|
|
126
214
|
|
127
215
|
child[:example_group][:full_description].should == "Object parent child"
|
128
216
|
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "parent example group" do
|
132
|
-
it "nests the parent's example group metadata" do
|
133
|
-
parent = Metadata.new
|
134
|
-
parent.process(Object, 'parent')
|
135
217
|
|
136
|
-
|
137
|
-
|
218
|
+
%w[# . ::].each do |char|
|
219
|
+
context "with a 2nd arg starting with #{char}" do
|
220
|
+
it "removes the space" do
|
221
|
+
m = Metadata.new
|
222
|
+
m.process(Array, "#{char}method")
|
223
|
+
m[:example_group][:full_description].should eq("Array#{char}method")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
138
227
|
|
139
|
-
|
228
|
+
%w[# . ::].each do |char|
|
229
|
+
context "with a nested description starting with #{char}" do
|
230
|
+
it "removes the space" do
|
231
|
+
parent = Metadata.new
|
232
|
+
parent.process("Object")
|
233
|
+
child = Metadata.new(parent)
|
234
|
+
child.process("#{char}method")
|
235
|
+
child[:example_group][:full_description].should eq("Object#{char}method")
|
236
|
+
end
|
237
|
+
end
|
140
238
|
end
|
141
239
|
end
|
142
240
|
|
143
|
-
describe "
|
241
|
+
describe ":file_path" do
|
144
242
|
it "finds the first non-rspec lib file in the caller array" do
|
145
243
|
m = Metadata.new
|
146
244
|
m.process(:caller => [
|
147
|
-
|
148
|
-
|
245
|
+
"./lib/rspec/core/foo.rb",
|
246
|
+
"#{__FILE__}:#{__LINE__}"
|
149
247
|
])
|
150
248
|
m[:example_group][:file_path].should == __FILE__
|
151
249
|
end
|
152
250
|
end
|
153
251
|
|
154
|
-
describe "
|
252
|
+
describe ":line_number" do
|
155
253
|
it "finds the line number with the first non-rspec lib file in the backtrace" do
|
156
254
|
m = Metadata.new
|
157
255
|
m.process({})
|
@@ -171,94 +269,17 @@ module RSpec
|
|
171
269
|
end
|
172
270
|
end
|
173
271
|
|
174
|
-
describe "
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
it "stores the description" do
|
180
|
-
mfe[:description].should == "example description"
|
181
|
-
end
|
182
|
-
|
183
|
-
it "stores the full_description (group description + example description)" do
|
184
|
-
mfe[:full_description].should == "group description example description"
|
185
|
-
end
|
186
|
-
|
187
|
-
it "creates an empty execution result" do
|
188
|
-
mfe[:execution_result].should == {}
|
189
|
-
end
|
190
|
-
|
191
|
-
it "extracts file path from caller" do
|
192
|
-
mfe[:file_path].should == __FILE__
|
193
|
-
end
|
194
|
-
|
195
|
-
it "extracts line number from caller" do
|
196
|
-
mfe[:line_number].should == line_number
|
197
|
-
end
|
198
|
-
|
199
|
-
it "extracts location from caller" do
|
200
|
-
mfe[:location].should == "#{__FILE__}:#{line_number}"
|
201
|
-
end
|
202
|
-
|
203
|
-
it "merges arbitrary options" do
|
204
|
-
mfe[:arbitrary].should == :options
|
205
|
-
end
|
206
|
-
|
207
|
-
it "points :example_group to the same hash object" do
|
208
|
-
a = metadata.for_example("foo", {})[:example_group]
|
209
|
-
b = metadata.for_example("bar", {})[:example_group]
|
210
|
-
a[:description] = "new description"
|
211
|
-
b[:description].should == "new description"
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "apply_condition" do
|
216
|
-
|
217
|
-
|
218
|
-
let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
219
|
-
let(:parent_group_line_number) { __LINE__ -1 }
|
220
|
-
let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
221
|
-
let(:group_line_number) { __LINE__ -1 }
|
222
|
-
let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
223
|
-
let(:example_line_number) { __LINE__ -1 }
|
224
|
-
let(:next_example_metadata) {group_metadata.for_example('next_example',
|
225
|
-
:caller => ["foo_spec.rb:#{example_line_number + 2}"])}
|
226
|
-
let(:world) { RSpec.world }
|
227
|
-
|
228
|
-
it "matches the group when the line_number is the example group line number" do
|
229
|
-
world.should_receive(:preceding_declaration_line).and_return(group_line_number)
|
230
|
-
# this call doesn't really make sense since apply_condition is only called
|
231
|
-
# for example metadata not group metadata
|
232
|
-
group_metadata.apply_condition(:line_number, group_line_number).should be_true
|
233
|
-
end
|
234
|
-
|
235
|
-
it "matches the example when the line_number is the grandparent example group line number" do
|
236
|
-
world.should_receive(:preceding_declaration_line).and_return(parent_group_line_number)
|
237
|
-
example_metadata.apply_condition(:line_number, parent_group_line_number).should be_true
|
238
|
-
end
|
239
|
-
|
240
|
-
it "matches the example when the line_number is the parent example group line number" do
|
241
|
-
world.should_receive(:preceding_declaration_line).and_return(group_line_number)
|
242
|
-
example_metadata.apply_condition(:line_number, group_line_number).should be_true
|
243
|
-
end
|
244
|
-
|
245
|
-
it "matches the example when the line_number is the example line number" do
|
246
|
-
world.should_receive(:preceding_declaration_line).and_return(example_line_number)
|
247
|
-
example_metadata.apply_condition(:line_number, example_line_number).should be_true
|
248
|
-
end
|
272
|
+
describe "child example group" do
|
273
|
+
it "nests the parent's example group metadata" do
|
274
|
+
parent = Metadata.new
|
275
|
+
parent.process(Object, 'parent')
|
249
276
|
|
250
|
-
|
251
|
-
|
252
|
-
example_metadata.apply_condition(:line_number, example_line_number + 1).should be_true
|
253
|
-
end
|
277
|
+
child = Metadata.new(parent)
|
278
|
+
child.process()
|
254
279
|
|
255
|
-
|
256
|
-
world.should_receive(:preceding_declaration_line).and_return(example_line_number + 2)
|
257
|
-
example_metadata.apply_condition(:line_number, example_line_number + 2).should be_false
|
280
|
+
child[:example_group][:example_group].should == parent[:example_group]
|
258
281
|
end
|
259
|
-
|
260
282
|
end
|
261
|
-
|
262
283
|
end
|
263
284
|
end
|
264
285
|
end
|
@@ -10,6 +10,45 @@ RSpec::Matchers.define :be_pending_with do |message|
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
RSpec::Matchers.define :fail_with do |exception_klass|
|
14
|
+
match do |example|
|
15
|
+
failure_reason(example, exception_klass).nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
failure_message_for_should do |example|
|
19
|
+
"expected example to fail with a #{exception_klass} exception, but #{failure_reason(example, exception_klass)}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_reason(example, exception_klass)
|
23
|
+
result = example.metadata[:execution_result]
|
24
|
+
case
|
25
|
+
when example.metadata[:pending] then "was pending"
|
26
|
+
when result[:status] != 'failed' then result[:status]
|
27
|
+
when !result[:exception_encountered].is_a?(exception_klass) then "failed with a #{result[:exception_encountered].class}"
|
28
|
+
else nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec::Matchers.define :pass do
|
34
|
+
match do |example|
|
35
|
+
failure_reason(example).nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
failure_message_for_should do |example|
|
39
|
+
"expected example to pass, but #{failure_reason(example)}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def failure_reason(example)
|
43
|
+
result = example.metadata[:execution_result]
|
44
|
+
case
|
45
|
+
when example.metadata[:pending] then "was pending"
|
46
|
+
when result[:status] != 'passed' then result[:status]
|
47
|
+
else nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
13
52
|
describe "an example" do
|
14
53
|
context "with no block" do
|
15
54
|
it "is listed as pending with 'Not Yet Implemented'" do
|
@@ -23,7 +62,7 @@ describe "an example" do
|
|
23
62
|
end
|
24
63
|
|
25
64
|
context "with no args" do
|
26
|
-
it "is listed as pending with
|
65
|
+
it "is listed as pending with the default message" do
|
27
66
|
group = RSpec::Core::ExampleGroup.describe('group') do
|
28
67
|
it "does something" do
|
29
68
|
pending
|
@@ -31,7 +70,7 @@ describe "an example" do
|
|
31
70
|
end
|
32
71
|
example = group.examples.first
|
33
72
|
example.run(group.new, stub.as_null_object)
|
34
|
-
example.should be_pending_with(
|
73
|
+
example.should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
|
35
74
|
end
|
36
75
|
end
|
37
76
|
|
@@ -82,37 +121,106 @@ describe "an example" do
|
|
82
121
|
end
|
83
122
|
|
84
123
|
context "with a block" do
|
124
|
+
def run_example(*pending_args)
|
125
|
+
group = RSpec::Core::ExampleGroup.describe('group') do
|
126
|
+
it "does something" do
|
127
|
+
pending(*pending_args) { yield }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
example = group.examples.first
|
131
|
+
example.run(group.new, stub.as_null_object)
|
132
|
+
example
|
133
|
+
end
|
134
|
+
|
85
135
|
context "that fails" do
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
136
|
+
def run_example(*pending_args)
|
137
|
+
super(*pending_args) { raise ArgumentError.new }
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when given no options" do
|
141
|
+
it "is listed as pending with the supplied message" do
|
142
|
+
run_example("just because").should be_pending_with("just because")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "is listed as pending with the default message when no message is given" do
|
146
|
+
run_example.should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when given a truthy :if option" do
|
151
|
+
it "is listed as pending with the supplied message" do
|
152
|
+
run_example("just because", :if => true).should be_pending_with("just because")
|
153
|
+
end
|
154
|
+
|
155
|
+
it "is listed as pending with the default message when no message is given" do
|
156
|
+
run_example(:if => true).should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when given a falsey :if option" do
|
161
|
+
it "runs the example and fails" do
|
162
|
+
run_example( :if => false).should fail_with(ArgumentError)
|
163
|
+
run_example("just because", :if => false).should fail_with(ArgumentError)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when given a truthy :unless option" do
|
168
|
+
it "runs the example and fails" do
|
169
|
+
run_example( :unless => true).should fail_with(ArgumentError)
|
170
|
+
run_example("just because", :unless => true).should fail_with(ArgumentError)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "when given a falsey :unless option" do
|
175
|
+
it "is listed as pending with the supplied message" do
|
176
|
+
run_example("just because", :unless => false).should be_pending_with("just because")
|
177
|
+
end
|
178
|
+
|
179
|
+
it "is listed as pending with the default message when no message is given" do
|
180
|
+
run_example(:unless => false).should be_pending_with(RSpec::Core::Pending::DEFAULT_MESSAGE)
|
93
181
|
end
|
94
|
-
example = group.examples.first
|
95
|
-
example.run(group.new, stub.as_null_object)
|
96
|
-
example.should be_pending_with('just because')
|
97
182
|
end
|
98
183
|
end
|
99
184
|
|
100
185
|
context "that passes" do
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
186
|
+
def run_example(*pending_args)
|
187
|
+
super(*pending_args) { 3.should == 3 }
|
188
|
+
end
|
189
|
+
|
190
|
+
context "when given no options" do
|
191
|
+
it "fails with a PendingExampleFixedError" do
|
192
|
+
run_example("just because").should fail_with(RSpec::Core::PendingExampleFixedError)
|
193
|
+
run_example.should fail_with(RSpec::Core::PendingExampleFixedError)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "when given a truthy :if option" do
|
198
|
+
it "fails with a PendingExampleFixedError" do
|
199
|
+
run_example("just because", :if => true).should fail_with(RSpec::Core::PendingExampleFixedError)
|
200
|
+
run_example( :if => true).should fail_with(RSpec::Core::PendingExampleFixedError)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "when given a falsey :if option" do
|
205
|
+
it "runs the example and it passes" do
|
206
|
+
run_example( :if => false).should pass
|
207
|
+
run_example("just because", :if => false).should pass
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context "when given a truthy :unless option" do
|
212
|
+
it "runs the example and it passes" do
|
213
|
+
run_example( :unless => true).should pass
|
214
|
+
run_example("just because", :unless => true).should pass
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context "when given a falsey :unless option" do
|
219
|
+
it "fails with a PendingExampleFixedError" do
|
220
|
+
run_example("just because", :unless => false).should fail_with(RSpec::Core::PendingExampleFixedError)
|
221
|
+
run_example( :unless => false).should fail_with(RSpec::Core::PendingExampleFixedError)
|
108
222
|
end
|
109
|
-
example = group.examples.first
|
110
|
-
example.run(group.new, stub.as_null_object)
|
111
|
-
example.metadata[:pending].should be_false
|
112
|
-
example.metadata[:execution_result][:status].should == 'failed'
|
113
|
-
example.metadata[:execution_result][:exception_encountered].should be_a(RSpec::Core::PendingExampleFixedError)
|
114
223
|
end
|
115
224
|
end
|
116
225
|
end
|
117
|
-
|
118
226
|
end
|