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
@@ -1,5 +1,8 @@
1
1
  Feature: described class
2
2
 
3
+ If the first argument to the outermost example group is a class, the class is
4
+ exposed to each example via the described_class() method.
5
+
3
6
  Scenario: access the described class from the example
4
7
  Given a file named "spec/example_spec.rb" with:
5
8
  """
@@ -138,3 +138,79 @@ Feature: pending examples
138
138
  checks something
139
139
  (PENDING: Not Yet Implemented)
140
140
  """
141
+
142
+ Scenario: conditionally pending examples
143
+ Given a file named "conditionally_pending_spec.rb" with:
144
+ """
145
+ describe "a failing spec" do
146
+ def run_test; raise "failure"; end
147
+
148
+ it "is pending when pending with a true :if condition" do
149
+ pending("true :if", :if => true) { run_test }
150
+ end
151
+
152
+ it "fails when pending with a false :if condition" do
153
+ pending("false :if", :if => false) { run_test }
154
+ end
155
+
156
+ it "is pending when pending with a false :unless condition" do
157
+ pending("false :unless", :unless => false) { run_test }
158
+ end
159
+
160
+ it "fails when pending with a true :unless condition" do
161
+ pending("true :unless", :unless => true) { run_test }
162
+ end
163
+ end
164
+
165
+ describe "a passing spec" do
166
+ def run_test; true.should be(true); end
167
+
168
+ it "fails when pending with a true :if condition" do
169
+ pending("true :if", :if => true) { run_test }
170
+ end
171
+
172
+ it "passes when pending with a false :if condition" do
173
+ pending("false :if", :if => false) { run_test }
174
+ end
175
+
176
+ it "fails when pending with a false :unless condition" do
177
+ pending("false :unless", :unless => false) { run_test }
178
+ end
179
+
180
+ it "passes when pending with a true :unless condition" do
181
+ pending("true :unless", :unless => true) { run_test }
182
+ end
183
+ end
184
+ """
185
+ When I run "rspec ./conditionally_pending_spec.rb"
186
+ Then the output should contain "8 examples, 4 failures, 2 pending"
187
+ And the output should contain:
188
+ """
189
+ Pending:
190
+ a failing spec is pending when pending with a true :if condition
191
+ # true :if
192
+ # ./conditionally_pending_spec.rb:4
193
+ a failing spec is pending when pending with a false :unless condition
194
+ # false :unless
195
+ # ./conditionally_pending_spec.rb:12
196
+ """
197
+ And the output should contain:
198
+ """
199
+ 1) a failing spec fails when pending with a false :if condition
200
+ Failure/Error: def run_test; raise "failure"; end
201
+ """
202
+ And the output should contain:
203
+ """
204
+ 2) a failing spec fails when pending with a true :unless condition
205
+ Failure/Error: def run_test; raise "failure"; end
206
+ """
207
+ And the output should contain:
208
+ """
209
+ 3) a passing spec fails when pending with a true :if condition FIXED
210
+ Expected pending 'true :if' to fail. No Error was raised.
211
+ """
212
+ And the output should contain:
213
+ """
214
+ 4) a passing spec fails when pending with a false :unless condition FIXED
215
+ Expected pending 'false :unless' to fail. No Error was raised.
216
+ """
@@ -0,0 +1,11 @@
1
+ Then /^the output should contain all of these:$/ do |table|
2
+ table.raw.flatten.each do |string|
3
+ assert_partial_output(string)
4
+ end
5
+ end
6
+
7
+ Then /^the output should not contain any of these:$/ do |table|
8
+ table.raw.flatten.each do |string|
9
+ combined_output.should_not =~ compile_and_escape(string)
10
+ end
11
+ end
@@ -1,5 +1,13 @@
1
1
  Feature: attribute of subject
2
2
 
3
+ Use the its() method as a short-hand to generate a nested example group with
4
+ a single example that specifies the expected value of an attribute of the subject.
5
+ This can be used with an implicit or explicit subject.
6
+
7
+ its() accepts a symbol or a string, and a block representing the example. Use
8
+ a string with dots to specify a nested attribute (i.e. an attribute of the
9
+ attribute of the subject).
10
+
3
11
  Scenario: simple attribute
4
12
  Given a file named "example_spec.rb" with:
5
13
  """
@@ -1,12 +1,11 @@
1
1
  Feature: explicit subject
2
2
 
3
- You can override the implicit subject using the subject() method.
4
-
3
+ Use subject() in the group scope to explicitly define the value that is
4
+ returned by the subject() method in the example scope.
5
+
5
6
  Scenario: subject in top level group
6
7
  Given a file named "top_level_subject_spec.rb" with:
7
8
  """
8
- require 'rspec/expectations'
9
-
10
9
  describe Array, "with some elements" do
11
10
  subject { [1,2,3] }
12
11
  it "should have the prescribed elements" do
@@ -14,14 +13,12 @@ Feature: explicit subject
14
13
  end
15
14
  end
16
15
  """
17
- When I run "rspec ./top_level_subject_spec.rb"
16
+ When I run "rspec top_level_subject_spec.rb"
18
17
  Then the output should contain "1 example, 0 failures"
19
18
 
20
19
  Scenario: subject in a nested group
21
20
  Given a file named "nested_subject_spec.rb" with:
22
21
  """
23
- require 'rspec/expectations'
24
-
25
22
  describe Array do
26
23
  subject { [1,2,3] }
27
24
  describe "with some elements" do
@@ -31,7 +28,7 @@ Feature: explicit subject
31
28
  end
32
29
  end
33
30
  """
34
- When I run "rspec ./nested_subject_spec.rb"
31
+ When I run "rspec nested_subject_spec.rb"
35
32
  Then the output should contain "1 example, 0 failures"
36
33
 
37
34
  Scenario: access subject from before block
@@ -45,14 +42,12 @@ Feature: explicit subject
45
42
  end
46
43
  end
47
44
  """
48
- When I run "rspec ./top_level_subject_spec.rb"
45
+ When I run "rspec top_level_subject_spec.rb"
49
46
  Then the output should contain "1 example, 0 failures"
50
47
 
51
- Scenario: subject using helper method
48
+ Scenario: invoke helper method from subject block
52
49
  Given a file named "helper_subject_spec.rb" with:
53
50
  """
54
- require 'rspec/expectations'
55
-
56
51
  describe Array do
57
52
  def prepared_array; [1,2,3] end
58
53
  subject { prepared_array }
@@ -63,5 +58,5 @@ Feature: explicit subject
63
58
  end
64
59
  end
65
60
  """
66
- When I run "rspec ./helper_subject_spec.rb"
61
+ When I run "rspec helper_subject_spec.rb"
67
62
  Then the output should contain "1 example, 0 failures"
@@ -0,0 +1,29 @@
1
+ Feature: implicit receiver
2
+
3
+ When should() is called in an example without an explicit receiver, it is
4
+ invoked against the subject (explicit or implicit).
5
+
6
+ Scenario: implicit subject
7
+ Given a file named "example_spec.rb" with:
8
+ """
9
+ describe Array do
10
+ describe "when first created" do
11
+ it { should be_empty }
12
+ end
13
+ end
14
+ """
15
+ When I run "rspec example_spec.rb"
16
+ Then the output should contain "1 example, 0 failures"
17
+
18
+ Scenario: explicit subject
19
+ Given a file named "example_spec.rb" with:
20
+ """
21
+ describe Array do
22
+ describe "with 3 items" do
23
+ subject { [1,2,3] }
24
+ it { should_not be_empty }
25
+ end
26
+ end
27
+ """
28
+ When I run "rspec example_spec.rb"
29
+ Then the output should contain "1 example, 0 failures"
@@ -1,15 +1,14 @@
1
1
  Feature: implicit subject
2
2
 
3
- The first argument to the outermost example group block is
4
- made available to each example as an implicit subject of
5
- that example.
6
-
3
+ If the first argument to the outermost example group is a class, an instance
4
+ of that class is exposed to each example via the subject() method.
5
+
7
6
  Scenario: subject in top level group
8
7
  Given a file named "top_level_subject_spec.rb" with:
9
8
  """
10
9
  describe Array, "when first created" do
11
10
  it "should be empty" do
12
- subject.should == []
11
+ subject.should eq([])
13
12
  end
14
13
  end
15
14
  """
@@ -22,10 +21,10 @@ Feature: implicit subject
22
21
  describe Array do
23
22
  describe "when first created" do
24
23
  it "should be empty" do
25
- subject.should == []
24
+ subject.should eq([])
26
25
  end
27
26
  end
28
27
  end
29
28
  """
30
- When I run "rspec ./nested_subject_spec.rb"
29
+ When I run "rspec nested_subject_spec.rb"
31
30
  Then the output should contain "1 example, 0 failures"
@@ -1,6 +1,7 @@
1
1
  require 'rspec/core/extensions'
2
2
  require 'rspec/core/load_path'
3
3
  require 'rspec/core/deprecation'
4
+ require 'rspec/core/backward_compatibility'
4
5
  require 'rspec/core/reporter'
5
6
 
6
7
  require 'rspec/core/hooks'
@@ -24,27 +25,12 @@ require 'rspec/core/version'
24
25
  require 'rspec/core/errors'
25
26
 
26
27
  module RSpec
27
- module Core
28
+ autoload :Matchers, 'rspec/matchers'
28
29
 
30
+ module Core
29
31
  def self.install_directory
30
32
  @install_directory ||= File.expand_path(File.dirname(__FILE__))
31
33
  end
32
-
33
- def self.configuration
34
- RSpec.deprecate('RSpec::Core.configuration', 'RSpec.configuration', '2.0.0')
35
- RSpec.configuration
36
- end
37
-
38
- def self.configure
39
- RSpec.deprecate('RSpec::Core.configure', 'RSpec.configure', '2.0.0')
40
- yield RSpec.configuration if block_given?
41
- end
42
-
43
- def self.world
44
- RSpec.deprecate('RSpec::Core.world', 'RSpec.world', '2.0.0')
45
- RSpec.world
46
- end
47
-
48
34
  end
49
35
 
50
36
  def self.wants_to_quit
@@ -73,8 +59,4 @@ module RSpec
73
59
  end
74
60
 
75
61
  require 'rspec/core/backward_compatibility'
76
-
77
- # TODO - make this configurable with default 'on'
78
- require 'rspec/expectations'
79
-
80
62
  require 'rspec/monkey'
@@ -9,11 +9,11 @@ module RSpec
9
9
  DEPRECATION WARNING: you are using a deprecated constant that will
10
10
  be removed from a future version of RSpec.
11
11
 
12
+ #{caller(0)[2]}
13
+
12
14
  * #{name} is deprecated.
13
15
  * RSpec is the new top-level module in RSpec-2
14
-
15
- #{caller(0)[1]}
16
- *****************************************************************
16
+ ***************************************************************
17
17
  WARNING
18
18
  RSpec
19
19
  else
@@ -21,9 +21,28 @@ WARNING
21
21
  end
22
22
  end
23
23
  end
24
+ end
24
25
 
26
+ module Runner
27
+ def self.configure(&block)
28
+ RSpec.deprecate("Spec::Runner.configure", "RSpec.configure")
29
+ RSpec.configure(&block)
30
+ end
25
31
  end
26
32
 
33
+ module Rake
34
+ def self.const_missing(name)
35
+ case name
36
+ when :SpecTask
37
+ RSpec.deprecate("Spec::Rake::SpecTask", "RSpec::Core::RakeTask")
38
+ require 'rspec/core/rake_task'
39
+ RSpec::Core::RakeTask
40
+ else
41
+ super(name)
42
+ end
43
+ end
44
+
45
+ end
27
46
  end
28
47
 
29
48
  Object.extend(RSpec::Core::ConstMissing)
@@ -17,6 +17,7 @@ module RSpec
17
17
  @options.configure(@configuration)
18
18
  @configuration.load_spec_files
19
19
  @configuration.configure_mock_framework
20
+ @configuration.configure_expectation_framework
20
21
  @world.announce_inclusion_filter
21
22
  @world.announce_exclusion_filter
22
23
 
@@ -27,6 +27,7 @@ module RSpec
27
27
  add_setting :fail_fast, :default => false
28
28
  add_setting :run_all_when_everything_filtered
29
29
  add_setting :mock_framework, :default => :rspec
30
+ add_setting :expectation_framework, :default => :rspec
30
31
  add_setting :filter
31
32
  add_setting :exclusion_filter
32
33
  add_setting :filename_pattern, :default => '**/*_spec.rb'
@@ -46,6 +47,11 @@ module RSpec
46
47
  /spec\/spec_helper\.rb/,
47
48
  /lib\/rspec\/(core|expectations|matchers|mocks)/
48
49
  ]
50
+
51
+ filter_run_excluding(
52
+ :if => lambda { |value, metadata| metadata.has_key?(:if) && !value },
53
+ :unless => lambda { |value| value }
54
+ )
49
55
  end
50
56
 
51
57
  # :call-seq:
@@ -125,6 +131,19 @@ module RSpec
125
131
  end
126
132
  end
127
133
 
134
+ def expect_with(expectation_framework)
135
+ settings[:expectation_framework] = expectation_framework
136
+ end
137
+
138
+ def require_expectation_framework_adapter
139
+ require case expectation_framework.to_s
140
+ when /rspec/i
141
+ 'rspec/core/expecting/with_rspec'
142
+ else
143
+ raise ArgumentError, "#{expectation_framework.inspect} is not supported"
144
+ end
145
+ end
146
+
128
147
  def full_backtrace=(bool)
129
148
  settings[:backtrace_clean_patterns] = []
130
149
  end
@@ -181,11 +200,11 @@ EOM
181
200
  end
182
201
 
183
202
  def line_number=(line_number)
184
- filter_run :line_number => line_number.to_i
203
+ filter_run({ :line_number => line_number.to_i }, true)
185
204
  end
186
205
 
187
206
  def full_description=(description)
188
- filter_run :full_description => /#{description}/
207
+ filter_run({ :full_description => /#{description}/ }, true)
189
208
  end
190
209
 
191
210
  attr_writer :formatter_class
@@ -260,19 +279,23 @@ EOM
260
279
  RSpec::Core::ExampleGroup.alias_it_should_behave_like_to(new_name, report_label)
261
280
  end
262
281
 
263
- def filter_run_including(options={})
282
+ def filter_run_including(options={}, force_overwrite = false)
264
283
  if filter and filter[:line_number] || filter[:full_description]
265
284
  warn "Filtering by #{options.inspect} is not possible since " \
266
285
  "you are already filtering by #{filter.inspect}"
267
286
  else
268
- self.filter = options
287
+ if force_overwrite
288
+ self.filter = options
289
+ else
290
+ self.filter = (filter || {}).merge(options)
291
+ end
269
292
  end
270
293
  end
271
294
 
272
295
  alias_method :filter_run, :filter_run_including
273
296
 
274
297
  def filter_run_excluding(options={})
275
- self.exclusion_filter = options
298
+ self.exclusion_filter = (exclusion_filter || {}).merge(options)
276
299
  end
277
300
 
278
301
  def include(mod, filters={})
@@ -290,7 +313,7 @@ EOM
290
313
  }
291
314
 
292
315
  include_or_extend_modules.each do |include_or_extend, mod, filters|
293
- next unless group.all_apply?(filters)
316
+ next unless group.apply?(:all?, filters)
294
317
  next if modules[include_or_extend].include?(mod)
295
318
  modules[include_or_extend] << mod
296
319
  group.send(include_or_extend, mod)
@@ -302,6 +325,11 @@ EOM
302
325
  RSpec::Core::ExampleGroup.send(:include, RSpec::Core::MockFrameworkAdapter)
303
326
  end
304
327
 
328
+ def configure_expectation_framework
329
+ require_expectation_framework_adapter
330
+ RSpec::Core::ExampleGroup.send(:include, RSpec::Core::ExpectationFrameworkAdapter)
331
+ end
332
+
305
333
  def load_spec_files
306
334
  files_to_run.map {|f| load File.expand_path(f) }
307
335
  end
@@ -91,9 +91,7 @@ module RSpec
91
91
 
92
92
  def local_options_file(options)
93
93
  return options[:options_file] if options[:options_file]
94
- return LOCAL_OPTIONS_FILE if File.exist?(LOCAL_OPTIONS_FILE)
95
- RSpec.deprecate("spec/spec.opts", "./.rspec or ~/.rspec", "2.0.0") if File.exist?("spec/spec.opts")
96
- "spec/spec.opts"
94
+ LOCAL_OPTIONS_FILE
97
95
  end
98
96
  end
99
97
  end