rspec-core 2.8.0.rc1 → 2.8.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/License.txt +24 -0
  2. data/README.md +197 -37
  3. data/features/command_line/format_option.feature +3 -3
  4. data/features/command_line/init.feature +18 -0
  5. data/features/example_groups/shared_examples.feature +1 -1
  6. data/features/hooks/around_hooks.feature +4 -4
  7. data/features/pending/pending_examples.feature +5 -5
  8. data/features/support/env.rb +8 -1
  9. data/lib/autotest/rspec2.rb +2 -6
  10. data/lib/rspec/core.rb +48 -158
  11. data/lib/rspec/core/backward_compatibility.rb +2 -0
  12. data/lib/rspec/core/command_line.rb +4 -0
  13. data/lib/rspec/core/configuration.rb +201 -106
  14. data/lib/rspec/core/configuration_options.rb +2 -1
  15. data/lib/rspec/core/deprecation.rb +2 -3
  16. data/lib/rspec/core/drb_options.rb +69 -58
  17. data/lib/rspec/core/dsl.rb +12 -0
  18. data/lib/rspec/core/example.rb +53 -18
  19. data/lib/rspec/core/example_group.rb +144 -54
  20. data/lib/rspec/core/extensions.rb +4 -4
  21. data/lib/rspec/core/extensions/instance_eval_with_args.rb +5 -0
  22. data/lib/rspec/core/extensions/kernel.rb +1 -1
  23. data/lib/rspec/core/extensions/module_eval_with_args.rb +4 -0
  24. data/lib/rspec/core/extensions/ordered.rb +7 -2
  25. data/lib/rspec/core/filter_manager.rb +69 -36
  26. data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
  27. data/lib/rspec/core/formatters/html_formatter.rb +10 -4
  28. data/lib/rspec/core/hooks.rb +93 -34
  29. data/lib/rspec/core/let.rb +62 -61
  30. data/lib/rspec/core/metadata.rb +103 -80
  31. data/lib/rspec/core/metadata_hash_builder.rb +4 -0
  32. data/lib/rspec/core/option_parser.rb +42 -44
  33. data/lib/rspec/core/pending.rb +25 -3
  34. data/lib/rspec/core/project_initializer.rb +62 -0
  35. data/lib/rspec/core/rake_task.rb +7 -13
  36. data/lib/rspec/core/runner.rb +2 -2
  37. data/lib/rspec/core/shared_context.rb +1 -1
  38. data/lib/rspec/core/shared_example_group.rb +11 -5
  39. data/lib/rspec/core/subject.rb +3 -3
  40. data/lib/rspec/core/version.rb +1 -1
  41. data/lib/rspec/monkey.rb +1 -1
  42. data/lib/rspec/monkey/spork/test_framework/rspec.rb +2 -0
  43. data/spec/command_line/order_spec.rb +19 -13
  44. data/spec/rspec/core/command_line_spec.rb +1 -5
  45. data/spec/rspec/core/configuration_options_spec.rb +22 -27
  46. data/spec/rspec/core/configuration_spec.rb +32 -14
  47. data/spec/rspec/core/drb_command_line_spec.rb +20 -37
  48. data/spec/rspec/core/drb_options_spec.rb +51 -3
  49. data/spec/rspec/core/example_group_spec.rb +101 -84
  50. data/spec/rspec/core/example_spec.rb +14 -0
  51. data/spec/rspec/core/filter_manager_spec.rb +114 -33
  52. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +17 -69
  53. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +14 -4
  54. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +14 -4
  55. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +14 -4
  56. data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -1
  57. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +20 -72
  58. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +24 -14
  59. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +29 -19
  60. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +29 -19
  61. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -2
  62. data/spec/rspec/core/metadata_spec.rb +77 -45
  63. data/spec/rspec/core/option_parser_spec.rb +5 -0
  64. data/spec/rspec/core/pending_example_spec.rb +44 -12
  65. data/spec/rspec/core/project_initializer_spec.rb +130 -0
  66. data/spec/rspec/core/rake_task_spec.rb +1 -1
  67. data/spec/spec_helper.rb +2 -0
  68. data/spec/support/matchers.rb +2 -12
  69. metadata +18 -16
  70. data/features/command_line/configure.feature +0 -22
  71. data/lib/rspec/core/command_line_configuration.rb +0 -62
  72. data/lib/rspec/core/errors.rb +0 -13
  73. data/spec/rspec/core/command_line_configuration_spec.rb +0 -26
@@ -0,0 +1,24 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009 Chad Humphries, David Chelimsky
4
+ Copyright (c) 2006 David Chelimsky, The RSpec Development Team
5
+ Copyright (c) 2005 Steven Baker
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,67 +1,227 @@
1
1
  # rspec-core
2
2
 
3
- rspec-core provides the structure for writing executable examples of how your
4
- code should behave.
5
-
6
- ## Install
7
-
8
- gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
9
- gem install rspec-core # for rspec-core only
3
+ ```
4
+ gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
5
+ gem install rspec-core # for rspec-core only
6
+ ```
7
+
8
+ # overview
9
+
10
+ rspec-core provides the structure for writing executable examples of how
11
+ your code should behave. It uses the words "describe" and "it" so we can
12
+ express concepts like a conversation:
13
+
14
+ "Describe an order."
15
+ "It sums the prices of its line items."
16
+
17
+ ## basic structure
18
+
19
+ ```ruby
20
+ describe Order do
21
+ it "sums the prices of its line items" do
22
+ order = Order.new
23
+ order.add_entry(LineItem.new(:item => Item.new(
24
+ :price => Money.new(1.11, :USD)
25
+ )))
26
+ order.add_entry(LineItem.new(:item => Item.new(
27
+ :price => Money.new(2.22, :USD),
28
+ :quantity => 2
29
+ )))
30
+ order.total.should eq(Money.new(5.55, :USD))
31
+ end
32
+ end
33
+ ```
34
+
35
+ The `describe` method creates an [ExampleGroup](../RSpec/Core/ExampleGroup). Within the
36
+ block passed to `describe` you can declare examples using the `it` method.
37
+
38
+ Under the hood, an example group is a class in which the block passed to
39
+ `describe` is evaluated. The blocks passed to `it` are evaluated in the
40
+ context of an _instance_ of that class.
41
+
42
+ ## nested groups
43
+
44
+ You can also declare nested nested groups using the `describe` or `context`
45
+ methods:
46
+
47
+ ```ruby
48
+ describe Order do
49
+ context "with no items" do
50
+ it "behaves one way" do
51
+ # ...
52
+ end
53
+ end
10
54
 
11
- ## Upgrading from rspec-1.x
55
+ context "with one item" do
56
+ it "behaves another way" do
57
+ # ...
58
+ end
59
+ end
60
+ end
61
+ ```
62
+
63
+ ## aliases
64
+
65
+ You can declare example groups using either `describe` or `context`, though
66
+ only `describe` is available at the top level.
67
+
68
+ You can declare examples within a group using any of `it`, `specify`, or
69
+ `example`.
70
+
71
+ ## shared examples and contexts
72
+
73
+ Declare a shared example group using `shared_examples`, and then include it
74
+ in any group using `include_examples`.
75
+
76
+ ```ruby
77
+ shared_examples "collections" do |collection_class|
78
+ it "is empty when first created" do
79
+ collection_class.new.should be_empty
80
+ end
81
+ end
82
+
83
+ describe Array do
84
+ include_examples "collections", Array
85
+ end
86
+
87
+ describe Hash do
88
+ include_examples "collections", Hash
89
+ end
90
+ ```
91
+
92
+ Nearly anything that can be declared within an example group can be declared
93
+ within a shared example group. This includes `before`, `after`, and `around`
94
+ hooks, `let` declarations, and nested groups/contexts.
95
+
96
+ You can also use the names `shared_context` and `include_context`. These are
97
+ pretty much the same as `shared_examples` and `include_examples`, providing
98
+ more accurate naming for in which you share hooks, `let` declarations, helper
99
+ methods, etc, but no examples.
100
+
101
+ ## metadata
102
+
103
+ rspec-core stores a metadata hash with every example and group, which
104
+ contains like their descriptions, the locations at which they were
105
+ declared, etc, etc. This hash powers many of rspec-core's features,
106
+ including output formatters (which access descriptions and locations),
107
+ and filtering before and after hooks.
108
+
109
+ Although you probably won't ever need this unless you are writing an
110
+ extension, you can access it from an example like this:
111
+
112
+ ```ruby
113
+ it "does something" do
114
+ example.metadata[:description].should eq("does something")
115
+ end
116
+ ```
117
+
118
+ ### `described_class`
119
+
120
+ When a class is passed to `describe`, you can access it from an example
121
+ using the `described_class` method, which is a wrapper for
122
+ `example.metadata[:described_class]`.
123
+
124
+ ```ruby
125
+ describe Widget do
126
+ example do
127
+ described_class.should equal(Widget)
128
+ end
129
+ end
130
+ ```
131
+
132
+ This is useful in extensions or shared example groups in which the specific
133
+ class is unknown. Taking the shared examples example from above, we can
134
+ clean it up a bit using `described_class`:
135
+
136
+ ```ruby
137
+ shared_examples "collections" do
138
+ it "is empty when first created" do
139
+ described.new.should be_empty
140
+ end
141
+ end
142
+
143
+ describe Array do
144
+ include_examples "collections"
145
+ end
146
+
147
+ describe Hash do
148
+ include_examples "collections"
149
+ end
150
+ ```
151
+
152
+ ## the `rspec` command
153
+
154
+ When you install the rspec-core gem, it installs the `rspec` executable,
155
+ which you'll use to run rspec. The `rspec` comes with many useful options.
156
+ Run `rspec --help` to see the complete list.
157
+ ## see also
12
158
 
13
- See [features/Upgrade.md](http://github.com/rspec/rspec-core/blob/master/features/Upgrade.md)
159
+ * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
160
+ * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
161
+ * [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
14
162
 
15
- ## Get Started
163
+ ## get started
16
164
 
17
165
  Start with a simple example of behavior you expect from your system. Do
18
166
  this before you write any implementation code:
19
167
 
20
- # in spec/calculator_spec.rb
21
- describe Calculator do
22
- it "add(x,y) returns the sum of its arguments" do
23
- Calculator.new.add(1, 2).should eq(3)
24
- end
25
- end
168
+ ```ruby
169
+ # in spec/calculator_spec.rb
170
+ describe Calculator do
171
+ it "add(x,y) returns the sum of its arguments" do
172
+ Calculator.new.add(1, 2).should eq(3)
173
+ end
174
+ end
175
+ ```
26
176
 
27
177
  Run this with the rspec command, and watch it fail:
28
178
 
29
- $ rspec spec/calculator_spec.rb
30
- ./spec/calculator_spec.rb:1: uninitialized constant Calculator
179
+ ```
180
+ $ rspec spec/calculator_spec.rb
181
+ ./spec/calculator_spec.rb:1: uninitialized constant Calculator
182
+ ```
31
183
 
32
184
  Implement the simplest solution:
33
185
 
34
- # in lib/calculator.rb
35
- class Calculator
36
- def add(a,b)
37
- a + b
38
- end
39
- end
186
+ ```ruby
187
+ # in lib/calculator.rb
188
+ class Calculator
189
+ def add(a,b)
190
+ a + b
191
+ end
192
+ end
193
+ ```
40
194
 
41
195
  Be sure to require the implementation file in the spec:
42
196
 
43
- # in spec/calculator_spec.rb
44
- # - RSpec adds ./lib to the $LOAD_PATH
45
- require "calculator"
197
+ ```ruby
198
+ # in spec/calculator_spec.rb
199
+ # - RSpec adds ./lib to the $LOAD_PATH
200
+ require "calculator"
201
+ ```
46
202
 
47
203
  Now run the spec again, and watch it pass:
48
204
 
49
- $ rspec spec/calculator_spec.rb
50
- .
205
+ ```
206
+ $ rspec spec/calculator_spec.rb
207
+ .
51
208
 
52
- Finished in 0.000315 seconds
53
- 1 example, 0 failures
209
+ Finished in 0.000315 seconds
210
+ 1 example, 0 failures
211
+ ```
54
212
 
55
213
  Use the `documentation` formatter to see the resulting spec:
56
214
 
57
- $ rspec spec/calculator_spec.rb --format doc
58
- Calculator add
59
- returns the sum of its arguments
215
+ ```
216
+ $ rspec spec/calculator_spec.rb --format doc
217
+ Calculator add
218
+ returns the sum of its arguments
60
219
 
61
- Finished in 0.000379 seconds
62
- 1 example, 0 failures
220
+ Finished in 0.000379 seconds
221
+ 1 example, 0 failures
222
+ ```
63
223
 
64
- ## See also
224
+ ## Also see
65
225
 
66
226
  * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
67
227
  * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
@@ -56,7 +56,7 @@ Feature: --format option
56
56
  something
57
57
  does something that passes
58
58
  does something that fails (FAILED - 1)
59
- does something that is pending (PENDING: Not Yet Implemented)
59
+ does something that is pending (PENDING: No reason given)
60
60
  """
61
61
 
62
62
  Scenario: documentation format saved to a file
@@ -66,7 +66,7 @@ Feature: --format option
66
66
  something
67
67
  does something that passes
68
68
  does something that fails (FAILED - 1)
69
- does something that is pending (PENDING: Not Yet Implemented)
69
+ does something that is pending (PENDING: No reason given)
70
70
  """
71
71
 
72
72
  Scenario: multiple formats
@@ -77,5 +77,5 @@ Feature: --format option
77
77
  something
78
78
  does something that passes
79
79
  does something that fails (FAILED - 1)
80
- does something that is pending (PENDING: Not Yet Implemented)
80
+ does something that is pending (PENDING: No reason given)
81
81
  """
@@ -0,0 +1,18 @@
1
+ Feature: --init option
2
+
3
+ Use the --init option on the command line to generate conventional
4
+ files for an rspec project.
5
+
6
+ Scenario: generate .rspec
7
+ When I run `rspec --init`
8
+ Then the following files should exist:
9
+ | .rspec |
10
+ And the output should contain "create .rspec"
11
+
12
+ Scenario: .rspec file already exists
13
+ Given a file named ".rspec" with:
14
+ """
15
+ --color
16
+ """
17
+ When I run `rspec --init`
18
+ Then the output should contain "exist .rspec"
@@ -27,7 +27,7 @@ Feature: shared examples
27
27
  2. Put files containing shared examples in `spec/support/` and require files
28
28
  in that directory from `spec/spec_helper.rb`:
29
29
 
30
- Dir["spec/support/**/*.rb"].each {|f| require f}
30
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
31
31
 
32
32
  This is included in the generated `spec/spec_helper.rb` file in
33
33
  `rspec-rails`
@@ -199,7 +199,7 @@ Feature: around hooks
199
199
  When I run `rspec example_spec.rb`
200
200
  Then the output should contain "1 example, 0 failure"
201
201
 
202
- Scenario: implicitly pending examples are detected as Not Yet Implemented
202
+ Scenario: implicitly pending examples are detected as Not yet implemented
203
203
  Given a file named "example_spec.rb" with:
204
204
  """
205
205
  describe "implicit pending example" do
@@ -207,7 +207,7 @@ Feature: around hooks
207
207
  example.run
208
208
  end
209
209
 
210
- it "should be detected as Not Yet Implemented"
210
+ it "should be detected as Not yet implemented"
211
211
  end
212
212
  """
213
213
  When I run `rspec example_spec.rb`
@@ -215,8 +215,8 @@ Feature: around hooks
215
215
  And the output should contain:
216
216
  """
217
217
  Pending:
218
- implicit pending example should be detected as Not Yet Implemented
219
- # Not Yet Implemented
218
+ implicit pending example should be detected as Not yet implemented
219
+ # Not yet implemented
220
220
  """
221
221
 
222
222
 
@@ -13,7 +13,7 @@ Feature: pending examples
13
13
  When I run `rspec example_without_block_spec.rb`
14
14
  Then the exit status should be 0
15
15
  And the output should contain "1 example, 0 failures, 1 pending"
16
- And the output should contain "Not Yet Implemented"
16
+ And the output should contain "Not yet implemented"
17
17
  And the output should contain "example_without_block_spec.rb:2"
18
18
 
19
19
  Scenario: pending any arbitary reason, with no block
@@ -98,13 +98,13 @@ Feature: pending examples
98
98
  """
99
99
  Pending:
100
100
  an example is pending using xit
101
- # Not Yet Implemented
101
+ # Temporarily disabled with xit
102
102
  # ./temporarily_pending_spec.rb:2
103
103
  an example is pending using xspecify
104
- # Not Yet Implemented
104
+ # Temporarily disabled with xspecify
105
105
  # ./temporarily_pending_spec.rb:5
106
106
  an example is pending using xexample
107
- # Not Yet Implemented
107
+ # Temporarily disabled with xexample
108
108
  # ./temporarily_pending_spec.rb:8
109
109
  """
110
110
 
@@ -149,7 +149,7 @@ Feature: pending examples
149
149
  """
150
150
  an example
151
151
  checks something
152
- (PENDING: Not Yet Implemented)
152
+ (PENDING: No reason given)
153
153
  """
154
154
 
155
155
  Scenario: conditionally pending examples
@@ -1,5 +1,12 @@
1
1
  require 'aruba/cucumber'
2
2
 
3
3
  Before do
4
- RUBY_PLATFORM =~ /java/ ? @aruba_timeout_seconds = 60 : @aruba_timeout_seconds = 5
4
+ if RUBY_PLATFORM =~ /java/
5
+ # ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
6
+ set_env('JRUBY_OPTS', '-X-C') # disable JIT since these processes are so short lived
7
+ set_env('JAVA_OPTS', '-d32') # force jRuby to use client JVM for faster startup times
8
+ @aruba_timeout_seconds = 60
9
+ else
10
+ @aruba_timeout_seconds = 5
11
+ end
5
12
  end
@@ -1,8 +1,6 @@
1
1
  require 'autotest'
2
2
  require 'rspec/core/deprecation'
3
3
 
4
- class RSpecCommandError < StandardError; end
5
-
6
4
  class Autotest::Rspec2 < Autotest
7
5
 
8
6
  RSPEC_EXECUTABLE = File.expand_path('../../../exe/rspec', __FILE__)
@@ -55,19 +53,17 @@ class Autotest::Rspec2 < Autotest
55
53
  end
56
54
  end
57
55
 
58
- # @private
56
+ private
57
+
59
58
  def suffix
60
59
  using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
61
60
  end
62
61
 
63
- # @private
64
62
  def using_bundler?
65
63
  prefix =~ /bundle exec/
66
64
  end
67
65
 
68
- # @private
69
66
  def gemfile?
70
67
  File.exist?('./Gemfile')
71
68
  end
72
-
73
69
  end