rspec-core 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/Gemfile +8 -3
  2. data/Guardfile +5 -0
  3. data/History.markdown +32 -2
  4. data/README.markdown +10 -3
  5. data/Rakefile +12 -13
  6. data/Upgrade.markdown +175 -121
  7. data/bin/autospec +13 -0
  8. data/bin/rspec +24 -1
  9. data/features/command_line/line_number_appended_to_path.feature +3 -1
  10. data/features/command_line/line_number_option.feature +3 -1
  11. data/features/command_line/tag.feature +74 -0
  12. data/features/filtering/exclusion_filters.feature +1 -1
  13. data/features/filtering/implicit_filters.feature +166 -0
  14. data/features/hooks/around_hooks.feature +51 -44
  15. data/features/metadata/described_class.feature +3 -0
  16. data/features/pending/pending_examples.feature +76 -0
  17. data/features/step_definitions/additional_cli_steps.rb +11 -0
  18. data/features/subject/attribute_of_subject.feature +8 -0
  19. data/features/subject/explicit_subject.feature +8 -13
  20. data/features/subject/implicit_receiver.feature +29 -0
  21. data/features/subject/implicit_subject.feature +6 -7
  22. data/lib/rspec/core.rb +3 -21
  23. data/lib/rspec/core/backward_compatibility.rb +22 -3
  24. data/lib/rspec/core/command_line.rb +1 -0
  25. data/lib/rspec/core/configuration.rb +34 -6
  26. data/lib/rspec/core/configuration_options.rb +1 -3
  27. data/lib/rspec/core/example.rb +0 -5
  28. data/lib/rspec/core/example_group.rb +9 -8
  29. data/lib/rspec/core/expecting/with_rspec.rb +11 -0
  30. data/lib/rspec/core/extensions/object.rb +1 -1
  31. data/lib/rspec/core/formatters/base_formatter.rb +1 -6
  32. data/lib/rspec/core/hooks.rb +1 -1
  33. data/lib/rspec/core/metadata.rb +15 -5
  34. data/lib/rspec/core/option_parser.rb +17 -0
  35. data/lib/rspec/core/pending.rb +10 -1
  36. data/lib/rspec/core/rake_task.rb +32 -10
  37. data/lib/rspec/core/reporter.rb +1 -0
  38. data/lib/rspec/core/subject.rb +58 -59
  39. data/lib/rspec/core/version.rb +1 -1
  40. data/lib/rspec/core/world.rb +9 -4
  41. data/rspec-core.gemspec +4 -11
  42. data/spec/rspec/core/command_line_spec.rb +16 -5
  43. data/spec/rspec/core/configuration_options_spec.rb +6 -0
  44. data/spec/rspec/core/configuration_spec.rb +89 -6
  45. data/spec/rspec/core/deprecations_spec.rb +17 -1
  46. data/spec/rspec/core/example_group_spec.rb +29 -14
  47. data/spec/rspec/core/example_spec.rb +0 -7
  48. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +49 -33
  49. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
  50. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +46 -26
  51. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
  52. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +49 -33
  53. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +19 -19
  54. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +56 -33
  55. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +26 -38
  56. data/spec/rspec/core/metadata_spec.rb +153 -132
  57. data/spec/rspec/core/pending_example_spec.rb +133 -25
  58. data/spec/rspec/core/rake_task_spec.rb +25 -32
  59. data/spec/rspec/core/subject_spec.rb +15 -0
  60. data/spec/rspec/core/world_spec.rb +72 -61
  61. data/spec/spec_helper.rb +0 -14
  62. metadata +25 -135
  63. data/features/hooks/halt.feature +0 -26
data/Gemfile CHANGED
@@ -1,5 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ %w[rspec-core rspec-expectations rspec-mocks].each do |lib|
4
+ gem lib, :path => File.expand_path("../../#{lib}", __FILE__)
5
+ end
6
+
3
7
  gem "rake"
4
8
  gem "cucumber", "0.8.5"
5
9
  gem "aruba", "0.2.2"
@@ -11,9 +15,10 @@ gem "rr"
11
15
  gem "flexmock"
12
16
  gem "nokogiri"
13
17
  gem "syntax"
14
- gem "rspec-core", :path => "."
15
- gem "rspec-expectations", :path => "../rspec-expectations"
16
- gem "rspec-mocks", :path => "../rspec-mocks"
18
+ gem "relish", "~> 0.0.3"
19
+ gem "guard-rspec"
20
+ gem "growl"
21
+ gem "rb-fsevent"
17
22
 
18
23
  unless RUBY_PLATFORM == "java"
19
24
  gem "ruby-prof"
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch('^spec/(.*)_spec.rb')
3
+ watch('^lib/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('^spec/spec_helper.rb') { "spec" }
5
+ end
@@ -1,11 +1,41 @@
1
1
  ## rspec-core release history (incomplete)
2
2
 
3
+ ### 2.1.0 / 2010-11-07
4
+
5
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.1...v2.1.0)
6
+
7
+ * Enhancments
8
+ * Add skip_bundler option to rake task to tell rake task to ignore the
9
+ presence of a Gemfile (jfelchner)
10
+ * Add gemfile option to rake task to tell rake task what Gemfile to look
11
+ for (defaults to 'Gemfile')
12
+ * Allow passing caller trace into Metadata to support extensions (Glenn
13
+ Vanderburg)
14
+ * Add deprecation warning for Spec::Runner.configure to aid upgrade from
15
+ RSpec-1
16
+ * Add deprecated Spec::Rake::SpecTask to aid upgrade from RSpec-1
17
+ * Add 'autospec' command with helpful message to aid upgrade from RSpec-1
18
+ * Add support for filtering with tags on CLI (Lailson Bandeira)
19
+ * Add a helpful message about RUBYOPT when require fails in bin/rspec
20
+ (slyphon)
21
+ * Add "-Ilib" to the default rcov options (Tianyi Cui)
22
+ * Make the expectation framework configurable (default rspec, of course)
23
+ (Justin Ko)
24
+ * Add 'pending' to be conditional (Myron Marston)
25
+ * Add explicit support for :if and :unless as metadata keys for conditional run
26
+ of examples (Myron Marston)
27
+ * Add --fail-fast command line option (Jeff Kreeftmeijer)
28
+
29
+ * Bug fixes
30
+ * Eliminate stack overflow with "subject { self }"
31
+ * Require 'rspec/core' in the Raketask (ensures it required when running rcov)
32
+
3
33
  ### 2.0.1 / 2010-10-18
4
34
 
5
35
  [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0...v2.0.1)
6
36
 
7
37
  * Bug fixes
8
- * restore color when using spork + autotest
38
+ * Restore color when using spork + autotest
9
39
  * Pending examples without docstrings render the correct message (Josep M. Bach)
10
40
  * Fixed bug where a failure in a spec file ending in anything but _spec.rb would
11
41
  fail in a confusing way.
@@ -28,7 +58,7 @@
28
58
 
29
59
  * Enhancements
30
60
  * implicitly require unknown formatters so you don't have to require the
31
- file explicitly on the commmand line (Michael Grosser)
61
+ file explicitly on the commmand line (Michael Grosser)
32
62
  * add --out/-o option to assign output target
33
63
  * added fail_fast configuration option to abort on first failure
34
64
  * support a Hash subject (its([:key]) { should == value }) (Josep M. Bach)
@@ -2,13 +2,20 @@
2
2
 
3
3
  Behaviour Driven Development for Ruby
4
4
 
5
- ## Upgrading from rspec-1.x
5
+ ## Documentation
6
6
 
7
- See [Upgrade.markdown](http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)
7
+ * [Cucumber features](http://relishapp.com/rspec/rspec-core/v/2-0)
8
+ * [RDoc](http://rubydoc.info/gems/rspec-core/2.0.1/frames)
8
9
 
9
10
  ## Install
10
11
 
11
- gem install rspec -v 2.0.0
12
+ gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
13
+ gem install rspec-core # for rspec-core only
14
+
15
+ ## Upgrading from rspec-1.x
16
+
17
+ See [Upgrade.markdown](http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)
18
+
12
19
 
13
20
  This will install the rspec, rspec-core, rspec-expectations and rspec-mocks
14
21
  gems.
data/Rakefile CHANGED
@@ -18,10 +18,6 @@ class Cucumber::Rake::Task::ForkedCucumberRunner
18
18
  end
19
19
  end
20
20
 
21
- task :cleanup_rcov_files do
22
- rm_rf 'coverage.data'
23
- end
24
-
25
21
  desc "Run all examples"
26
22
  RSpec::Core::RakeTask.new(:spec) do |t|
27
23
  t.rspec_path = 'bin/rspec'
@@ -30,25 +26,28 @@ end
30
26
 
31
27
  Cucumber::Rake::Task.new(:cucumber)
32
28
 
33
- namespace :spec do
34
- desc "Run all examples using rcov"
35
- RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
29
+ namespace :rcov do
30
+ task :cleanup do
31
+ rm_rf 'coverage.data'
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new :spec do |t|
36
35
  t.rcov = true
37
36
  t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
38
- t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
37
+ t.rcov_opts << %[--no-html --aggregate coverage.data]
39
38
  end
40
- end
41
39
 
42
- namespace :cucumber do
43
- desc "Run cucumber features using rcov"
44
- Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
40
+ Cucumber::Rake::Task.new :cucumber do |t|
45
41
  t.cucumber_opts = %w{--format progress}
46
42
  t.rcov = true
47
43
  t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
48
44
  t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
49
45
  end
46
+
50
47
  end
51
48
 
49
+ task :rcov => ["rcov:cleanup", "rcov:spec", "rcov:cucumber"]
50
+
52
51
  task :default => [:spec, :cucumber]
53
52
 
54
53
  task :clobber do
@@ -60,7 +59,7 @@ end
60
59
  desc "Push cukes to relishapp using the relish-client-gem"
61
60
  task :relish, :version do |t, args|
62
61
  raise "rake relish[VERSION]" unless args[:version]
63
- sh "bundle exec relish --organization rspec --project rspec-core -v #{args[:version]} push"
62
+ sh "relish push --organization rspec --project rspec-core -v #{args[:version]}"
64
63
  end
65
64
 
66
65
  Rake::RDocTask.new do |rdoc|
@@ -1,148 +1,67 @@
1
- # Upgrade to rspec-core-2.0
1
+ # New features in rspec-core-2.1
2
2
 
3
- ## What's changed since RSpec-1
3
+ ## Command line
4
4
 
5
- ### rspec command
6
-
7
- The command to run specs is now `rspec` instead of `spec`.
8
-
9
- rspec ./spec
10
-
11
- #### Co-habitation of rspec-1 and rspec-2
12
-
13
- Early beta versions of RSpec-2 included a `spec` command, which conflicted with
14
- the RSpec-1 `spec` command because RSpec-1's was installed by the rspec gem,
15
- while RSpec-2's is installed by the rspec-core gem.
16
-
17
- If you installed one of these early versions, the safest bet is to uninstall
18
- rspec-1 and rspec-core-2, and then reinstall both. After you do this, you will
19
- be able to run rspec-2 like this:
20
-
21
- `rspec ./spec`
22
-
23
- ... and rspec-1 like this:
24
-
25
- `spec _1.3.1_ ./spec`
26
-
27
- Rubygems inspects the first argument to any gem executable to see if it's
28
- formatted like a version number surrounded by underscores. If so, it uses that
29
- version (e.g. `1.3.1`). If not, it uses the most recent version (e.g.
30
- `2.0.0`).
31
-
32
- ### rake task
33
-
34
- The RSpec rake task has moved to:
35
-
36
- 'rspec/core/rake_task'
37
-
38
- RCov options are now set directly on the Rake task:
39
-
40
- RSpec::Core::RakeTask.new(:rcov) do |t|
41
- t.rcov_opts = %q[--exclude "spec"]
42
- end
43
-
44
- In RSpec-1, the rake task would read in rcov options from an `rcov.opts`
45
- file. This is ignored by RSpec-2.
46
-
47
- ### autotest
48
-
49
- RSpec-2 works with autotest as follows:
50
-
51
- rspec --configure autotest
52
-
53
- This adds `./autotest/discover.rb` with:
54
-
55
- Autotest.add_discovery { "rspec2" }
56
-
57
- Now, on the command line just type:
58
-
59
- autotest
60
-
61
- Or, if you're using bundler:
62
-
63
- bundle exec autotest
64
-
65
- The `autospec` command is a thing of the past.
66
-
67
- ### RSpec is the new Spec
68
-
69
- The root namespace (top level module) is now `RSpec` instead of `Spec`, and
70
- the root directory under `lib` within all of the `rspec` gems is `rspec` instead of `spec`.
5
+ ### `--tags`
71
6
 
72
- ### Configuration
73
-
74
- Typically in `spec/spec_helper.rb`, configuration is now done like this:
7
+ Now you can tag groups and examples using metadata and access those tags from
8
+ the command line. So if you have a group with `:foo => true`:
75
9
 
76
- RSpec.configure do |c|
77
- # ....
10
+ describe "something", :foo => true do
11
+ it "does something" do
12
+ # ...
13
+ end
78
14
  end
79
15
 
80
- ### .rspec
16
+ ... now you can run just that group like this:
81
17
 
82
- Command line options can be persisted in a `.rspec` file in a project. You
83
- can also store a `.rspec` file in your home directory (`~/.rspec`) with global
84
- options. Precedence is:
18
+ rspec spec --tags foo
85
19
 
86
- command line
87
- ./.rspec
88
- ~/.rspec
20
+ ### `--fail-fast`
89
21
 
90
- ### Bones
22
+ Add this flag to the command line to tell rspec to clean up and exit after the
23
+ first failure:
91
24
 
92
- Bones produces a handy little Rakefile to provide several services including
93
- running specs. The current version (3.4.7) still assumes RSpec-1. To bring its
94
- Rakefile into conformance with RSpec-2 a few changes are necessary.
25
+ rspec spec --fail-fast
95
26
 
96
- 1. The require line has changed to `require 'spec/rake/spectask'`
27
+ ## Metata/filtering
97
28
 
98
- 2. The `spec_opts` accessor has been deprecated in favor of `rspec_opts`. Also,
99
- the `rspec` command no longer supports the `--options` command line option
100
- so the options must be embedded directly in the Rakefile, or stored in the
101
- `.rspec` files mentioned above.
29
+ ### :if and :unless keys
102
30
 
103
- 3. The `spec_files` accessor has been replaced by `pattern`.
104
-
105
- Here is a complete example:
106
-
107
- # rspec-1
108
- Spec::Rake::SpecTask.new do |t|
109
- t.spec_opts = ['--options', "\"spec/spec.opts\""]
110
- t.spec_files = FileList['spec/**/*.rb']
111
- end
112
-
113
- becomes:
31
+ Use :if and :unless keys to conditionally run examples with simple boolean
32
+ expressions:
114
33
 
115
- # rspec-2
116
- RSpec::Core::RakeTask.new do |t|
117
- t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
118
- t.pattern = 'spec/**/*_spec.rb'
34
+ describe "something" do
35
+ it "does something", :if => RUBY_VERSION == 1.8.6 do
36
+ # ...
37
+ end
38
+ it "does something", :unless => RUBY_VERSION == 1.8.6 do
39
+ # ...
40
+ end
119
41
  end
120
42
 
121
- ### `context` is no longer a top-level method
43
+ ## Conditionally 'pending' examples
122
44
 
123
- We removed `context` from the main object because it was creating conflicts with
124
- IRB and some users who had `Context` domain objects. `describe` is still there,
125
- so if you want to use `context` at the top level, just alias it:
126
-
127
- alias :context :describe
128
-
129
- Of course, you can still use `context` to declare a nested group:
45
+ Make examples pending based on a condition. This is most useful when you
46
+ have an example that runs in multiple contexts and fails in one of those due to
47
+ a bug in a third-party dependency that you expect to be fixed in the future.
130
48
 
131
49
  describe "something" do
132
- context "in some context" do
133
- it "does something" do
134
- # ...
50
+ it "does something that doesn't yet work right on JRuby" do
51
+ pending("waiting for the JRuby team to fix issue XYZ", :if => RUBY_PLATFORM == 'java') do
52
+ # the content of your spec
135
53
  end
136
54
  end
137
55
  end
138
56
 
139
- ### `$KCODE` no longer set implicitly to `'u'`
57
+ This example would run normally on all ruby interpretters except JRuby. On JRuby,
58
+ it uses the block form of `pending`, which causes the example to still be run and
59
+ will remain pending as long as it fails. In the future, if you upgraded your
60
+ JRuby installation to a newer release that allows the example to pass, RSpec
61
+ will report it as a failure (`Expected pending '...' to fail. No Error was raised.`),
62
+ so that know that you can remove the call to `pending`.
140
63
 
141
- In RSpec-1, the runner set `$KCODE` to `'u'`, which impacts, among other
142
- things, the behaviour of Regular Expressions when applied to non-ascii
143
- characters. This is no longer the case in RSpec-2.
144
-
145
- ## What's new
64
+ # New features in rspec-core-2.0
146
65
 
147
66
  ### Runner
148
67
 
@@ -233,3 +152,138 @@ NOTICE: The including example groups no longer have access to any of the
233
152
  methods, hooks, or state defined inside a shared group. This will break specs
234
153
  that were using shared example groups to extend the behavior of including
235
154
  groups in any way besides their intended purpose: to add examples to a group.
155
+
156
+ # Upgrading from rspec-1.x
157
+
158
+ ### rspec command
159
+
160
+ The command to run specs is now `rspec` instead of `spec`.
161
+
162
+ rspec ./spec
163
+
164
+ #### Co-habitation of rspec-1 and rspec-2
165
+
166
+ Early beta versions of RSpec-2 included a `spec` command, which conflicted with
167
+ the RSpec-1 `spec` command because RSpec-1's was installed by the rspec gem,
168
+ while RSpec-2's is installed by the rspec-core gem.
169
+
170
+ If you installed one of these early versions, the safest bet is to uninstall
171
+ rspec-1 and rspec-core-2, and then reinstall both. After you do this, you will
172
+ be able to run rspec-2 like this:
173
+
174
+ rspec ./spec
175
+
176
+ ... and rspec-1 like this:
177
+
178
+ spec _1.3.1_ ./spec
179
+
180
+ Rubygems inspects the first argument to any gem executable to see if it's
181
+ formatted like a version number surrounded by underscores. If so, it uses that
182
+ version (e.g. `1.3.1`). If not, it uses the most recent version (e.g.
183
+ `2.0.0`).
184
+
185
+ ### rake task
186
+
187
+ A few things changed in the Rake task used to run specs:
188
+
189
+ 1. The file in which it is defined changed from `spec/rake/spectask` to
190
+ `rspec/core/rake_task`
191
+
192
+ 2. The `spec_opts` accessor has been deprecated in favor of `rspec_opts`. Also,
193
+ the `rspec` command no longer supports the `--options` command line option
194
+ so the options must be embedded directly in the Rakefile, or stored in the
195
+ `.rspec` files mentioned above.
196
+
197
+ 3. In RSpec-1, the rake task would read in rcov options from an `rcov.opts`
198
+ file. This is ignored by RSpec-2. RCov options are now set directly on the Rake
199
+ task:
200
+
201
+ RSpec::Core::RakeTask.new(:rcov) do |t|
202
+ t.rcov_opts = %q[--exclude "spec"]
203
+ end
204
+
205
+ 3. The `spec_files` accessor has been replaced by `pattern`.
206
+
207
+ # rspec-1
208
+ require 'spec/rake/spectask'
209
+
210
+ Spec::Rake::SpecTask.new do |t|
211
+ t.spec_opts = ['--options', "\"spec/spec.opts\""]
212
+ t.spec_files = FileList['spec/**/*.rb']
213
+ end
214
+
215
+ # rspec-2
216
+ require 'rspec/core/rake_task'
217
+
218
+ RSpec::Core::RakeTask.new do |t|
219
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
220
+ t.pattern = 'spec/**/*_spec.rb'
221
+ end
222
+
223
+ ### autotest
224
+
225
+ RSpec-2 works with autotest as follows:
226
+
227
+ rspec --configure autotest
228
+
229
+ This adds `./autotest/discover.rb` with:
230
+
231
+ Autotest.add_discovery { "rspec2" }
232
+
233
+ Now, on the command line just type:
234
+
235
+ autotest
236
+
237
+ Or, if you're using bundler:
238
+
239
+ bundle exec autotest
240
+
241
+ The `autospec` command is a thing of the past.
242
+
243
+ ### RSpec is the new Spec
244
+
245
+ The root namespace (top level module) is now `RSpec` instead of `Spec`, and
246
+ the root directory under `lib` within all of the `rspec` gems is `rspec` instead of `spec`.
247
+
248
+ ### Configuration
249
+
250
+ Typically in `spec/spec_helper.rb`, configuration is now done like this:
251
+
252
+ RSpec.configure do |c|
253
+ # ....
254
+ end
255
+
256
+ ### .rspec
257
+
258
+ Command line options can be persisted in a `.rspec` file in a project. You
259
+ can also store a `.rspec` file in your home directory (`~/.rspec`) with global
260
+ options. Precedence is:
261
+
262
+ command line
263
+ ./.rspec
264
+ ~/.rspec
265
+
266
+ ### `context` is no longer a top-level method
267
+
268
+ We removed `context` from the main object because it was creating conflicts with
269
+ IRB and some users who had `Context` domain objects. `describe` is still there,
270
+ so if you want to use `context` at the top level, just alias it:
271
+
272
+ alias :context :describe
273
+
274
+ Of course, you can still use `context` to declare a nested group:
275
+
276
+ describe "something" do
277
+ context "in some context" do
278
+ it "does something" do
279
+ # ...
280
+ end
281
+ end
282
+ end
283
+
284
+ ### `$KCODE` no longer set implicitly to `'u'`
285
+
286
+ In RSpec-1, the runner set `$KCODE` to `'u'`, which impacts, among other
287
+ things, the behaviour of Regular Expressions when applied to non-ascii
288
+ characters. This is no longer the case in RSpec-2.
289
+