rspec-core 2.0.0.beta.20 → 2.0.0.beta.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.rspec +1 -1
  2. data/Gemfile +7 -6
  3. data/History.md +30 -0
  4. data/Rakefile +3 -43
  5. data/bin/rspec +2 -1
  6. data/features/configuration/{options_file.feature → read_options_from_file.feature} +29 -25
  7. data/features/example_groups/shared_example_group.feature +10 -6
  8. data/features/hooks/before_and_after_hooks.feature +38 -0
  9. data/lib/autotest/rspec2.rb +10 -2
  10. data/lib/rspec/core.rb +8 -0
  11. data/lib/rspec/core/configuration.rb +16 -10
  12. data/lib/rspec/core/configuration_options.rb +7 -3
  13. data/lib/rspec/core/example.rb +7 -0
  14. data/lib/rspec/core/example_group.rb +15 -2
  15. data/lib/rspec/core/extensions/module_eval_with_args.rb +9 -29
  16. data/lib/rspec/core/extensions/object.rb +0 -2
  17. data/lib/rspec/core/formatters/base_formatter.rb +8 -6
  18. data/lib/rspec/core/formatters/base_text_formatter.rb +18 -10
  19. data/lib/rspec/core/formatters/documentation_formatter.rb +9 -9
  20. data/lib/rspec/core/option_parser.rb +0 -4
  21. data/lib/rspec/core/rake_task.rb +85 -39
  22. data/lib/rspec/core/reporter.rb +18 -5
  23. data/lib/rspec/core/runner.rb +8 -18
  24. data/lib/rspec/core/shared_example_group.rb +2 -1
  25. data/lib/rspec/core/version.rb +1 -1
  26. data/rspec-core.gemspec +33 -233
  27. data/spec/autotest/failed_results_re_spec.rb +1 -2
  28. data/spec/autotest/rspec_spec.rb +62 -42
  29. data/spec/rspec/core/configuration_options_spec.rb +12 -29
  30. data/spec/rspec/core/configuration_spec.rb +8 -8
  31. data/spec/rspec/core/example_group_spec.rb +38 -7
  32. data/spec/rspec/core/example_spec.rb +16 -1
  33. data/spec/rspec/core/formatters/base_formatter_spec.rb +6 -0
  34. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +125 -10
  35. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +36 -0
  36. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +282 -0
  37. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +22 -2
  38. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +280 -0
  39. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +280 -0
  40. data/spec/rspec/core/rake_task_spec.rb +128 -0
  41. data/spec/rspec/core/reporter_spec.rb +36 -0
  42. data/spec/rspec/core/runner_spec.rb +0 -18
  43. data/spec/rspec/core/shared_example_group_spec.rb +22 -2
  44. data/spec/rspec/core/world_spec.rb +13 -15
  45. data/spec/spec_helper.rb +2 -1
  46. metadata +110 -13
  47. data/VERSION +0 -1
  48. data/lib/rspec/autorun.rb +0 -2
@@ -0,0 +1,280 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
+ <head>
7
+ <title>RSpec results</title>
8
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
+ <meta http-equiv="Expires" content="-1" />
10
+ <meta http-equiv="Pragma" content="no-cache" />
11
+ <style type="text/css">
12
+ body {
13
+ margin: 0;
14
+ padding: 0;
15
+ background: #fff;
16
+ font-size: 80%;
17
+ }
18
+ </style>
19
+ <script type="text/javascript">
20
+ // <![CDATA[
21
+ function moveProgressBar(percentDone) {
22
+ document.getElementById("rspec-header").style.width = percentDone +"%";
23
+ }
24
+ function makeRed(element_id) {
25
+ document.getElementById(element_id).style.background = '#C40D0D';
26
+ document.getElementById(element_id).style.color = '#FFFFFF';
27
+ }
28
+
29
+ function makeYellow(element_id) {
30
+ if (element_id == "rspec-header" && document.getElementById(element_id).style.background != '#C40D0D')
31
+ {
32
+ document.getElementById(element_id).style.background = '#FAF834';
33
+ document.getElementById(element_id).style.color = '#000000';
34
+ }
35
+ else
36
+ {
37
+ document.getElementById(element_id).style.background = '#FAF834';
38
+ document.getElementById(element_id).style.color = '#000000';
39
+ }
40
+ }
41
+
42
+ // ]]>
43
+ </script>
44
+ <style type="text/css">
45
+ #rspec-header {
46
+ background: #65C400; color: #fff; height: 4em;
47
+ }
48
+
49
+ .rspec-report h1 {
50
+ margin: 0px 10px 0px 10px;
51
+ padding: 10px;
52
+ font-family: "Lucida Grande", Helvetica, sans-serif;
53
+ font-size: 1.8em;
54
+ position: absolute;
55
+ }
56
+
57
+ #summary {
58
+ margin: 0; padding: 5px 10px;
59
+ font-family: "Lucida Grande", Helvetica, sans-serif;
60
+ text-align: right;
61
+ top: 0px;
62
+ right: 0px;
63
+ float:right;
64
+ }
65
+
66
+ #summary p {
67
+ margin: 0 0 0 2px;
68
+ }
69
+
70
+ #summary #totals {
71
+ font-size: 1.2em;
72
+ }
73
+
74
+ .example_group {
75
+ margin: 0 10px 5px;
76
+ background: #fff;
77
+ }
78
+
79
+ dl {
80
+ margin: 0; padding: 0 0 5px;
81
+ font: normal 11px "Lucida Grande", Helvetica, sans-serif;
82
+ }
83
+
84
+ dt {
85
+ padding: 3px;
86
+ background: #65C400;
87
+ color: #fff;
88
+ font-weight: bold;
89
+ }
90
+
91
+ dd {
92
+ margin: 5px 0 5px 5px;
93
+ padding: 3px 3px 3px 18px;
94
+ }
95
+
96
+ dd.spec.passed {
97
+ border-left: 5px solid #65C400;
98
+ border-bottom: 1px solid #65C400;
99
+ background: #DBFFB4; color: #3D7700;
100
+ }
101
+
102
+ dd.spec.failed {
103
+ border-left: 5px solid #C20000;
104
+ border-bottom: 1px solid #C20000;
105
+ color: #C20000; background: #FFFBD3;
106
+ }
107
+
108
+ dd.spec.not_implemented {
109
+ border-left: 5px solid #FAF834;
110
+ border-bottom: 1px solid #FAF834;
111
+ background: #FCFB98; color: #131313;
112
+ }
113
+
114
+ dd.spec.pending_fixed {
115
+ border-left: 5px solid #0000C2;
116
+ border-bottom: 1px solid #0000C2;
117
+ color: #0000C2; background: #D3FBFF;
118
+ }
119
+
120
+ .backtrace {
121
+ color: #000;
122
+ font-size: 12px;
123
+ }
124
+
125
+ a {
126
+ color: #BE5C00;
127
+ }
128
+
129
+ /* Ruby code, style similar to vibrant ink */
130
+ .ruby {
131
+ font-size: 12px;
132
+ font-family: monospace;
133
+ color: white;
134
+ background-color: black;
135
+ padding: 0.1em 0 0.2em 0;
136
+ }
137
+
138
+ .ruby .keyword { color: #FF6600; }
139
+ .ruby .constant { color: #339999; }
140
+ .ruby .attribute { color: white; }
141
+ .ruby .global { color: white; }
142
+ .ruby .module { color: white; }
143
+ .ruby .class { color: white; }
144
+ .ruby .string { color: #66FF00; }
145
+ .ruby .ident { color: white; }
146
+ .ruby .method { color: #FFCC00; }
147
+ .ruby .number { color: white; }
148
+ .ruby .char { color: white; }
149
+ .ruby .comment { color: #9933CC; }
150
+ .ruby .symbol { color: white; }
151
+ .ruby .regex { color: #44B4CC; }
152
+ .ruby .punct { color: white; }
153
+ .ruby .escape { color: white; }
154
+ .ruby .interp { color: white; }
155
+ .ruby .expr { color: white; }
156
+
157
+ .ruby .offending { background-color: gray; }
158
+ .ruby .linenum {
159
+ width: 75px;
160
+ padding: 0.1em 1em 0.2em 0;
161
+ color: #000000;
162
+ background-color: #FFFBD3;
163
+ }
164
+
165
+ </style>
166
+ </head>
167
+ <body>
168
+ <div class="rspec-report">
169
+
170
+ <div id="rspec-header">
171
+ <div id="label">
172
+ <h1>RSpec Code Examples</h1>
173
+ </div>
174
+
175
+ <div id="summary">
176
+ <p id="totals">&nbsp;</p>
177
+ <p id="duration">&nbsp;</p>
178
+ </div>
179
+ </div>
180
+
181
+ <div class="results">
182
+ <div class="example_group">
183
+ <dl>
184
+ <dt id="example_group_1">pending spec with no implementation</dt>
185
+ <script type="text/javascript">makeYellow('rspec-header');</script>
186
+ <script type="text/javascript">makeYellow('example_group_1');</script>
187
+ <script type="text/javascript">moveProgressBar('20.0');</script>
188
+ <dd class="spec not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not Yet Implemented)</span></dd>
189
+ </dl>
190
+ </div>
191
+ <div class="example_group">
192
+ <dl>
193
+ <dt id="example_group_2">pending command with block format</dt>
194
+ </dl>
195
+ </div>
196
+ <div class="example_group">
197
+ <dl>
198
+ <dt id="example_group_3">with content that would fail</dt>
199
+ <script type="text/javascript">makeYellow('rspec-header');</script>
200
+ <script type="text/javascript">makeYellow('example_group_3');</script>
201
+ <script type="text/javascript">moveProgressBar('40.0');</script>
202
+ <dd class="spec not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: No reason given)</span></dd>
203
+ </dl>
204
+ </div>
205
+ <div class="example_group">
206
+ <dl>
207
+ <dt id="example_group_4">with content that would pass</dt>
208
+ <script type="text/javascript">makeRed('rspec-header');</script>
209
+ <script type="text/javascript">makeRed('example_group_4');</script>
210
+ <script type="text/javascript">moveProgressBar('60.0');</script>
211
+ <dd class="spec pending_fixed">
212
+ <span class="failed_spec_name">fails</span>
213
+ <div class="failure" id="failure_0">
214
+ <div class="message"><pre>RSpec::Core::PendingExampleFixedError</pre></div>
215
+ <div class="backtrace"><pre>/Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb:19:in `block (3 levels) in <top (required)>'
216
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:23:in `block (2 levels) in <module:Formatters>'
217
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:45:in `block (5 levels) in <module:Formatters>'
218
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:45:in `open'
219
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:45:in `block (4 levels) in <module:Formatters>'
220
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:44:in `chdir'
221
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:44:in `block (3 levels) in <module:Formatters>'
222
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:70:in `block (3 levels) in <top (required)>'
223
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:44:in `instance_eval'
224
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:44:in `sandboxed'
225
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:70:in `block (2 levels) in <top (required)>'</pre></div>
226
+ <pre class="ruby"><code><span class="linenum">11</span> <span class="keyword">rescue</span> <span class="constant">Exception</span> <span class="punct">=&gt;</span> <span class="ident">e</span>
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>
231
+ </div>
232
+ </dd>
233
+ </dl>
234
+ </div>
235
+ <div class="example_group">
236
+ <dl>
237
+ <dt id="example_group_5">passing spec</dt>
238
+ <script type="text/javascript">moveProgressBar('80.0');</script>
239
+ <dd class="spec passed"><span class="passed_spec_name">passes</span></dd>
240
+ </dl>
241
+ </div>
242
+ <div class="example_group">
243
+ <dl>
244
+ <dt id="example_group_6">failing spec</dt>
245
+ <script type="text/javascript">makeRed('example_group_6');</script>
246
+ <script type="text/javascript">moveProgressBar('100.0');</script>
247
+ <dd class="spec failed">
248
+ <span class="failed_spec_name">fails</span>
249
+ <div class="failure" id="failure_0">
250
+ <div class="message"><pre>
251
+ expected 2
252
+ got 1
253
+
254
+ (compared using ==)
255
+ </pre></div>
256
+ <div class="backtrace"><pre>/Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/resources/formatter_specs.rb:34:in `block (2 levels) in <top (required)>'
257
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:23:in `block (2 levels) in <module:Formatters>'
258
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:45:in `block (5 levels) in <module:Formatters>'
259
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:45:in `open'
260
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:45:in `block (4 levels) in <module:Formatters>'
261
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:44:in `chdir'
262
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/rspec/core/formatters/text_mate_formatter_spec.rb:44:in `block (3 levels) in <module:Formatters>'
263
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:70:in `block (3 levels) in <top (required)>'
264
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:44:in `instance_eval'
265
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:44:in `sandboxed'
266
+ /Users/dchelimsky/projects/ruby/rspec2/repos/rspec-core/spec/spec_helper.rb:70:in `block (2 levels) in <top (required)>'</pre></div>
267
+ <pre class="ruby"><code><span class="linenum">27</span> <span class="keyword">end</span>
268
+ <span class="linenum">28</span>
269
+ <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>
270
+ <span class="linenum">30</span> <span class="keyword">end</span></code></pre>
271
+ </div>
272
+ </dd>
273
+ </dl>
274
+ </div>
275
+ <script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>x seconds</strong>";</script>
276
+ <script type="text/javascript">document.getElementById('totals').innerHTML = "5 examples, 2 failures, 2 pending";</script>
277
+ </div>
278
+ </div>
279
+ </body>
280
+ </html>
@@ -0,0 +1,128 @@
1
+ require "spec_helper"
2
+ require "rspec/core/rake_task"
3
+
4
+ module RSpec::Core
5
+ describe RakeTask do
6
+ let(:task) { RakeTask.new }
7
+
8
+ before do
9
+ File.stub(:exist?) { false }
10
+ end
11
+
12
+ def with_bundler
13
+ File.stub(:exist?) { true }
14
+ yield
15
+ end
16
+
17
+ def with_rcov
18
+ task.rcov = true
19
+ yield
20
+ end
21
+
22
+ def spec_command
23
+ task.__send__(:spec_command)
24
+ end
25
+
26
+ context "default" do
27
+ it "renders rspec" do
28
+ spec_command.should =~ /^-S rspec/
29
+ end
30
+ end
31
+
32
+ context "with bundler" do
33
+ it "renders bundle exec rspec" do
34
+ with_bundler do
35
+ spec_command.should =~ /^-S bundle exec rspec/
36
+ end
37
+ end
38
+ end
39
+
40
+ context "with rcov" do
41
+ it "renders rcov" do
42
+ with_rcov do
43
+ spec_command.should =~ /^-S rcov/
44
+ end
45
+ end
46
+ end
47
+
48
+ context "with bundler and rcov" do
49
+ it "renders bundle exec rcov" do
50
+ with_bundler do
51
+ with_rcov do
52
+ spec_command.should =~ /^-S bundle exec rcov/
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ context "with warnings on" do
59
+ before { RSpec.stub(:deprecate) }
60
+
61
+ it "renders -w before the -S" do
62
+ task.warning = true
63
+ spec_command.should =~ /^-w -S rspec/
64
+ end
65
+
66
+ it "warns about deprecation" do
67
+ RSpec.should_receive(:deprecate)
68
+ task.warning = true
69
+ end
70
+ end
71
+
72
+ context "with ruby options" do
73
+ it "renders them before -S" do
74
+ task.ruby_opts = "-w"
75
+ spec_command.should =~ /^-w -S rspec/
76
+ end
77
+ end
78
+
79
+ context "with rcov_opts" do
80
+ context "with rcov=false (default)" do
81
+ it "does not add the rcov options to the command" do
82
+ task.rcov_opts = '--exclude "mocks"'
83
+ spec_command.should_not =~ /--exclude "mocks"/
84
+ end
85
+ end
86
+
87
+ context "with rcov=true" do
88
+ it "renders them after rcov" do
89
+ task.rcov = true
90
+ task.rcov_opts = '--exclude "mocks"'
91
+ spec_command.should =~ /^-S rcov --exclude "mocks"/
92
+ end
93
+ end
94
+ end
95
+
96
+ context "with rspec_opts" do
97
+ context "with rcov=true" do
98
+ it "does not add the rspec_opts" do
99
+ task.rcov = true
100
+ task.rspec_opts = "-Ifoo"
101
+ spec_command.should_not =~ /-Ifoo/
102
+ end
103
+ end
104
+ context "with rcov=false (default)" do
105
+ it "adds the rspec_opts" do
106
+ task.rspec_opts = "-Ifoo"
107
+ spec_command.should =~ /rspec -Ifoo/
108
+ end
109
+ end
110
+ end
111
+
112
+ context "with spec_opts" do
113
+ before { RSpec.stub(:deprecate) }
114
+
115
+ it "warns about deprecation" do
116
+ RSpec.should_receive(:deprecate)
117
+ task.spec_opts = "-Ifoo"
118
+ end
119
+
120
+ it "adds options as rspec_opts" do
121
+ task.spec_opts = "-Ifoo"
122
+ spec_command.should =~ /rspec -Ifoo/
123
+ end
124
+
125
+ end
126
+
127
+ end
128
+ end
@@ -2,6 +2,19 @@ require "spec_helper"
2
2
 
3
3
  module RSpec::Core
4
4
  describe Reporter do
5
+ describe "abort" do
6
+ let(:formatter) { double("formatter").as_null_object }
7
+ let(:example) { double("example") }
8
+ let(:reporter) { Reporter.new(formatter) }
9
+
10
+ %w[start_dump dump_pending dump_failures dump_summary close].each do |message|
11
+ it "sends #{message} to the formatter(s)" do
12
+ formatter.should_receive(message)
13
+ reporter.abort
14
+ end
15
+ end
16
+ end
17
+
5
18
  context "given one formatter" do
6
19
  it "passes messages to that formatter" do
7
20
  formatter = double("formatter")
@@ -13,6 +26,29 @@ module RSpec::Core
13
26
 
14
27
  reporter.example_started(example)
15
28
  end
29
+
30
+ it "passes example_group_started and example_group_finished messages to that formatter in that order" do
31
+ order = []
32
+
33
+ formatter = stub("formatter")
34
+ formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
35
+ formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }
36
+
37
+ group = ExampleGroup.describe("root")
38
+ group.describe("context 1")
39
+ group.describe("context 2")
40
+
41
+ group.run_all(Reporter.new(formatter))
42
+
43
+ order.should == [
44
+ "Started: root",
45
+ "Started: context 1",
46
+ "Finished: context 1",
47
+ "Started: context 2",
48
+ "Finished: context 2",
49
+ "Finished: root"
50
+ ]
51
+ end
16
52
  end
17
53
 
18
54
  context "given multiple formatters" do