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

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.
Files changed (50) hide show
  1. data/.gitignore +1 -0
  2. data/Upgrade.markdown +6 -0
  3. data/VERSION +1 -1
  4. data/features/example_groups/shared_example_group.feature +44 -7
  5. data/features/filtering/exclusion_filters.feature +79 -0
  6. data/features/filtering/inclusion_filters.feature +1 -1
  7. data/features/hooks/around_hooks.feature +28 -1
  8. data/features/pending/pending_examples.feature +2 -4
  9. data/features/spec_files/arbitrary_file_suffix.feature +13 -0
  10. data/lib/autotest/rspec2.rb +17 -17
  11. data/lib/rspec/core.rb +2 -2
  12. data/lib/rspec/core/command_line.rb +2 -1
  13. data/lib/rspec/core/configuration.rb +23 -9
  14. data/lib/rspec/core/deprecation.rb +1 -1
  15. data/lib/rspec/core/example_group.rb +11 -28
  16. data/lib/rspec/core/extensions.rb +4 -0
  17. data/lib/rspec/core/extensions/instance_eval_with_args.rb +39 -0
  18. data/lib/rspec/core/{kernel_extensions.rb → extensions/kernel.rb} +0 -0
  19. data/lib/rspec/core/extensions/module_eval_with_args.rb +54 -0
  20. data/lib/rspec/core/{object_extensions.rb → extensions/object.rb} +3 -1
  21. data/lib/rspec/core/formatters/base_formatter.rb +20 -43
  22. data/lib/rspec/core/formatters/base_text_formatter.rb +13 -10
  23. data/lib/rspec/core/formatters/documentation_formatter.rb +4 -4
  24. data/lib/rspec/core/formatters/html_formatter.rb +4 -4
  25. data/lib/rspec/core/formatters/progress_formatter.rb +4 -4
  26. data/lib/rspec/core/rake_task.rb +1 -1
  27. data/lib/rspec/core/reporter.rb +65 -0
  28. data/lib/rspec/core/subject.rb +1 -1
  29. data/lib/rspec/core/world.rb +11 -3
  30. data/rspec-core.gemspec +26 -14
  31. data/spec/autotest/failed_results_re_spec.rb +14 -23
  32. data/spec/autotest/rspec_spec.rb +1 -1
  33. data/spec/rspec/core/configuration_spec.rb +74 -9
  34. data/spec/rspec/core/drb_command_line_spec.rb +2 -2
  35. data/spec/rspec/core/example_group_spec.rb +13 -7
  36. data/spec/rspec/core/example_spec.rb +4 -4
  37. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +280 -0
  38. data/spec/rspec/core/formatters/html_formatter_spec.rb +5 -3
  39. data/spec/rspec/core/formatters/progress_formatter_spec.rb +3 -3
  40. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +2 -2
  41. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +280 -0
  42. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +5 -3
  43. data/spec/rspec/core/hooks_filtering_spec.rb +104 -0
  44. data/spec/rspec/core/reporter_spec.rb +34 -0
  45. data/spec/rspec/core/shared_example_group_spec.rb +22 -2
  46. data/spec/rspec/core/world_spec.rb +10 -8
  47. data/spec/rspec/{core/core_spec.rb → core_spec.rb} +0 -0
  48. data/spec/ruby_forker.rb +1 -1
  49. data/spec/spec_helper.rb +2 -2
  50. metadata +39 -33
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ tmp
8
8
  tags
9
9
  rerun.txt
10
10
  Gemfile.lock
11
+ .bundle
@@ -8,6 +8,12 @@ The command to run specs is now `rspec` instead of `spec`.
8
8
 
9
9
  rspec ./spec
10
10
 
11
+ ### rake task
12
+
13
+ The RSpec rake task has moved to:
14
+
15
+ 'rspec/core/rake_task'
16
+
11
17
  ### autotest
12
18
 
13
19
  RSpec-2 works with autotest as follows:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.19
1
+ 2.0.0.beta.20
@@ -20,9 +20,11 @@ Feature: Shared example group
20
20
  end
21
21
  end
22
22
 
23
- describe "#first" do
24
- it "returns the first item" do
25
- @instance.first.should == 7
23
+ describe "#include?" do
24
+ context "with an an item in the collection" do
25
+ it "returns true" do
26
+ @instance.include?(7).should be_true
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -43,15 +45,17 @@ Feature: Shared example group
43
45
  it should behave like a collection object
44
46
  initialized with 3 items
45
47
  has three items
46
- #first
47
- returns the first item
48
+ #include?
49
+ with an an item in the collection
50
+ returns true
48
51
 
49
52
  Set
50
53
  it should behave like a collection object
51
54
  initialized with 3 items
52
55
  has three items
53
- #first
54
- returns the first item
56
+ #include?
57
+ with an an item in the collection
58
+ returns true
55
59
  """
56
60
 
57
61
  Scenario: Using a shared example group with a block
@@ -96,6 +100,39 @@ Feature: Shared example group
96
100
  adds objects to the end of the collection
97
101
  """
98
102
 
103
+ @wip
104
+ Scenario: Passing parameters to a shared example group
105
+ Given a file named "shared_example_group_params_spec.rb" with:
106
+ """
107
+ shared_examples_for "a measurable object" do |measurement_method, measurement|
108
+ it "should return #{measurement} from ##{measurement_method}" do
109
+ subject.send(measurement_method).should == measurement
110
+ end
111
+ end
112
+
113
+ describe Array, "with 3 items" do
114
+ subject { [1, 2, 3] }
115
+ it_should_behave_like "a measurable object", :size, 3
116
+ end
117
+
118
+ describe String, "of 6 characters" do
119
+ subject { "FooBar" }
120
+ it_should_behave_like "a measurable object", :length, 6
121
+ end
122
+ """
123
+ When I run "rspec shared_example_group_params_spec.rb --format documentation"
124
+ Then the output should contain "2 examples, 0 failures"
125
+ And the output should contain:
126
+ """
127
+ Array with 3 items
128
+ it should behave like a measurable object
129
+ should return 3 from #size
130
+
131
+ String of 6 characters
132
+ it should behave like a measurable object
133
+ should return 6 from #length
134
+ """
135
+
99
136
  Scenario: Aliasing "it_should_behave_like" to "it_has_behavior"
100
137
  Given a file named "shared_example_group_spec.rb" with:
101
138
  """
@@ -0,0 +1,79 @@
1
+ Feature: exclusion filters
2
+
3
+ Scenario: exclude one example
4
+ Given a file named "spec/sample_spec.rb" with:
5
+ """
6
+ RSpec.configure do |c|
7
+ c.filter_run_excluding :broken => true
8
+ end
9
+
10
+ describe "something" do
11
+ it "does one thing" do
12
+ end
13
+
14
+ it "does another thing", :broken => true do
15
+ end
16
+ end
17
+ """
18
+ When I run "rspec ./spec/sample_spec.rb --format doc"
19
+ Then the output should contain "does one thing"
20
+ And the output should not contain "does another thing"
21
+
22
+ Scenario: exclude one group
23
+ Given a file named "spec/sample_spec.rb" with:
24
+ """
25
+ RSpec.configure do |c|
26
+ c.filter_run_excluding :broken => true
27
+ end
28
+
29
+ describe "group 1", :broken => true do
30
+ it "group 1 example 1" do
31
+ end
32
+
33
+ it "group 1 example 2" do
34
+ end
35
+ end
36
+
37
+ describe "group 2" do
38
+ it "group 2 example 1" do
39
+ end
40
+ end
41
+ """
42
+ When I run "rspec ./spec/sample_spec.rb --format doc"
43
+ Then the output should contain "group 2 example 1"
44
+ And the output should not contain "group 1 example 1"
45
+ And the output should not contain "group 1 example 2"
46
+
47
+ Scenario: exclude all groups
48
+ Given a file named "spec/sample_spec.rb" with:
49
+ """
50
+ RSpec.configure do |c|
51
+ c.filter_run_excluding :broken => true
52
+ end
53
+
54
+ describe "group 1", :broken => true do
55
+ before(:all) do
56
+ raise "you should not see me"
57
+ end
58
+
59
+ it "group 1 example 1" do
60
+ end
61
+
62
+ it "group 1 example 2" do
63
+ end
64
+ end
65
+
66
+ describe "group 2", :broken => true do
67
+ before(:each) do
68
+ raise "you should not see me"
69
+ end
70
+
71
+ it "group 2 example 1" do
72
+ end
73
+ end
74
+ """
75
+ When I run "rspec ./spec/sample_spec.rb --format doc"
76
+ Then the output should contain "No examples were matched. Perhaps {:broken=>true} is excluding everything?"
77
+ And the output should contain "0 examples, 0 failures"
78
+ And the output should not contain "group 1"
79
+ And the output should not contain "group 2"
@@ -1,4 +1,4 @@
1
- Feature: inclusion feature
1
+ Feature: inclusion filters
2
2
 
3
3
  Scenario: focus on one example
4
4
  Given a file named "spec/sample_spec.rb" with:
@@ -27,6 +27,33 @@ Feature: around hooks
27
27
  around each after
28
28
  """
29
29
 
30
+ Scenario: argument passed to around hook can be treated as a proc
31
+ Given a file named "treat_around_hook_arg_as_a_proc.rb" with:
32
+ """
33
+ describe "around filter" do
34
+ def perform_around
35
+ puts "around each before"
36
+ yield
37
+ puts "around each after"
38
+ end
39
+
40
+ around(:each) do |example|
41
+ perform_around(&example)
42
+ end
43
+
44
+ it "gets run in order" do
45
+ puts "in the example"
46
+ end
47
+ end
48
+ """
49
+ When I run "rspec ./treat_around_hook_arg_as_a_proc.rb"
50
+ Then the output should contain:
51
+ """
52
+ around each before
53
+ in the example
54
+ around each after
55
+ """
56
+
30
57
  Scenario: around hooks defined globally are run
31
58
  Given a file named "ensure_around_blocks_are_run.rb" with:
32
59
  """
@@ -85,7 +112,7 @@ Feature: around hooks
85
112
  around each after
86
113
  """
87
114
 
88
- Scenario: before/after(:hooks) hooks are NOT wrapped by the around hook
115
+ Scenario: before/after(:all) hooks are NOT wrapped by the around hook
89
116
  Given a file named "ensure_around_blocks_are_run.rb" with:
90
117
  """
91
118
  describe "around filter" do
@@ -28,10 +28,9 @@ Feature: pending examples
28
28
  """
29
29
  When I run "rspec ./pending_without_block_spec.rb"
30
30
  Then the exit status should be 0
31
+ And the output should contain "1 example, 0 failures, 1 pending"
31
32
  And the output should contain:
32
33
  """
33
- 1 example, 0 failures, 1 pending
34
-
35
34
  Pending:
36
35
  an example is implemented but waiting
37
36
  # something else getting finished
@@ -51,10 +50,9 @@ Feature: pending examples
51
50
  """
52
51
  When I run "rspec ./pending_with_failing_block_spec.rb"
53
52
  Then the exit status should be 0
53
+ And the output should contain "1 example, 0 failures, 1 pending"
54
54
  And the output should contain:
55
55
  """
56
- 1 example, 0 failures, 1 pending
57
-
58
56
  Pending:
59
57
  an example is implemented but waiting
60
58
  # something else getting finished
@@ -0,0 +1,13 @@
1
+ Feature: arbitrary file suffix
2
+
3
+ Scenario: .spec
4
+ Given a file named "a.spec" with:
5
+ """
6
+ describe "something" do
7
+ it "does something" do
8
+ 3.should eq(3)
9
+ end
10
+ end
11
+ """
12
+ When I run "rspec a.spec"
13
+ Then the output should contain "1 example, 0 failures"
@@ -1,19 +1,5 @@
1
1
  require 'autotest'
2
2
 
3
- Autotest.add_hook :initialize do |at|
4
- at.clear_mappings
5
- # watch out for Ruby bug (1.8.6): %r(/) != /\//
6
- at.add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
7
- filename
8
- }
9
- at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
10
- ["spec/#{m[1]}_spec.rb"]
11
- }
12
- at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
13
- at.files_matching %r%^spec/.*_spec\.rb$%
14
- }
15
- end
16
-
17
3
  class RSpecCommandError < StandardError; end
18
4
 
19
5
  class Autotest::Rspec2 < Autotest
@@ -22,15 +8,29 @@ class Autotest::Rspec2 < Autotest
22
8
 
23
9
  def initialize
24
10
  super
25
- self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n\n?(.*?(\n\n\(.*?)?)\n\n/m
11
+ clear_mappings
12
+ setup_rspec_project_mappings
13
+ self.failed_results_re = /^\s*\d\)\s(.*?$\n.*?$).*?#\s(.*?):/m
26
14
  self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
27
15
  end
28
16
 
17
+ def setup_rspec_project_mappings
18
+ add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _|
19
+ filename
20
+ }
21
+ add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
22
+ ["spec/#{m[1]}_spec.rb"]
23
+ }
24
+ add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
25
+ files_matching %r%^spec/.*_spec\.rb$%
26
+ }
27
+ end
28
+
29
29
  def consolidate_failures(failed)
30
30
  filters = new_hash_of_arrays
31
31
  failed.each do |spec, trace|
32
- if trace =~ /\n(\.\/)?(.*spec\.rb):[\d]+:/
33
- filters[$2] << spec
32
+ if trace =~ /(.*spec\.rb)/
33
+ filters[$1] << spec
34
34
  end
35
35
  end
36
36
  return filters
@@ -1,7 +1,7 @@
1
- require 'rspec/core/kernel_extensions'
2
- require 'rspec/core/object_extensions'
1
+ require 'rspec/core/extensions'
3
2
  require 'rspec/core/load_path'
4
3
  require 'rspec/core/deprecation'
4
+ require 'rspec/core/reporter'
5
5
  require 'rspec/core/formatters'
6
6
 
7
7
  require 'rspec/core/hooks'
@@ -15,9 +15,10 @@ module RSpec
15
15
  @options.configure(@configuration)
16
16
  @configuration.error_stream = err
17
17
  @configuration.output_stream ||= out
18
- @configuration.require_files_to_run
18
+ @configuration.load_spec_files
19
19
  @configuration.configure_mock_framework
20
20
  @world.announce_inclusion_filter
21
+ @world.announce_exclusion_filter
21
22
 
22
23
  @configuration.reporter.report(example_count) do |reporter|
23
24
  begin
@@ -127,7 +127,7 @@ module RSpec
127
127
  def color_enabled=(bool)
128
128
  return unless bool
129
129
  settings[:color_enabled] = true
130
- if bool && ::Config::CONFIG['host_os'] =~ /mswin|mingw/
130
+ if bool && ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
131
131
  orig_output_stream = settings[:output_stream]
132
132
  begin
133
133
  require 'Win32/Console/ANSI'
@@ -204,7 +204,9 @@ EOM
204
204
  @formatter ||= formatter_class.new(output)
205
205
  end
206
206
 
207
- alias_method :reporter, :formatter
207
+ def reporter
208
+ @reporter ||= Reporter.new(formatter)
209
+ end
208
210
 
209
211
  def files_or_directories_to_run=(*files)
210
212
  self.files_to_run = files.flatten.collect do |file|
@@ -255,8 +257,12 @@ EOM
255
257
  end
256
258
 
257
259
  def filter_run_including(options={})
258
- # TODO (DC 2010-07-03) this should probably warn when the unless clause returns true
259
- self.filter = options unless filter and filter[:line_number] || filter[:full_description]
260
+ if filter and filter[:line_number] || filter[:full_description]
261
+ warn "Filtering by #{options.inspect} is not possible since " \
262
+ "you are already filtering by #{filter.inspect}"
263
+ else
264
+ self.filter = options
265
+ end
260
266
  end
261
267
 
262
268
  alias_method :filter_run, :filter_run_including
@@ -273,9 +279,17 @@ EOM
273
279
  include_or_extend_modules << [:extend, mod, filters]
274
280
  end
275
281
 
276
- def find_modules(group)
277
- include_or_extend_modules.select do |include_or_extend, mod, filters|
278
- group.all_apply?(filters)
282
+ def configure_group(group)
283
+ modules = {
284
+ :include => [] + group.included_modules,
285
+ :extend => [] + group.ancestors
286
+ }
287
+
288
+ include_or_extend_modules.each do |include_or_extend, mod, filters|
289
+ next unless group.all_apply?(filters)
290
+ next if modules[include_or_extend].include?(mod)
291
+ modules[include_or_extend] << mod
292
+ group.send(include_or_extend, mod)
279
293
  end
280
294
  end
281
295
 
@@ -284,8 +298,8 @@ EOM
284
298
  RSpec::Core::ExampleGroup.send(:include, RSpec::Core::MockFrameworkAdapter)
285
299
  end
286
300
 
287
- def require_files_to_run
288
- files_to_run.map {|f| require File.expand_path(f) }
301
+ def load_spec_files
302
+ files_to_run.map {|f| load File.expand_path(f) }
289
303
  end
290
304
  end
291
305
  end
@@ -37,7 +37,7 @@ ADDITIONAL
37
37
 
38
38
  def []=(k,v)
39
39
  RSpec.deprecate(@method, @alternate_method)
40
- super
40
+ super(k,v)
41
41
  end
42
42
 
43
43
  end
@@ -1,6 +1,8 @@
1
1
  module RSpec
2
2
  module Core
3
3
  class ExampleGroup
4
+ extend Extensions::ModuleEvalWithArgs
5
+ include Extensions::InstanceEvalWithArgs
4
6
  extend Hooks
5
7
  include Subject
6
8
  include Let
@@ -33,6 +35,7 @@ module RSpec
33
35
 
34
36
  delegate_to_metadata :description, :describes, :file_path
35
37
  alias_method :display_name, :description
38
+ alias_method :described_class, :describes
36
39
  end
37
40
 
38
41
  def self.define_example_method(name, extra_options={})
@@ -59,15 +62,15 @@ module RSpec
59
62
  alias_example_to :pending, :pending => true
60
63
 
61
64
  def self.define_shared_group_method(new_name, report_label=nil)
62
- report_label = "it should behave like" unless report_label
63
65
  module_eval(<<-END_RUBY, __FILE__, __LINE__)
64
- def self.#{new_name}(name, &customization_block)
66
+ def self.#{new_name}(name, *args, &customization_block)
65
67
  shared_block = world.shared_example_groups[name]
66
68
  raise "Could not find shared example group named \#{name.inspect}" unless shared_block
67
69
 
68
- shared_group = describe("#{report_label} \#{name}", &shared_block)
69
- shared_group.class_eval(&customization_block) if customization_block
70
- shared_group
70
+ describe("#{report_label || "it should behave like"} \#{name}") do
71
+ module_eval_with_args *args, &shared_block
72
+ module_eval &customization_block if customization_block
73
+ end
71
74
  end
72
75
  END_RUBY
73
76
  end
@@ -145,10 +148,7 @@ module RSpec
145
148
 
146
149
  def self.set_it_up(*args)
147
150
  @metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
148
-
149
- world.find_modules(self).each do |include_or_extend, mod, opts|
150
- send(include_or_extend, mod) unless mixins[include_or_extend].include?(mod)
151
- end
151
+ world.configure_group(self)
152
152
  end
153
153
 
154
154
  def self.before_all_ivars
@@ -176,7 +176,7 @@ module RSpec
176
176
  def self.eval_around_eachs(example_group_instance, wrapped_example)
177
177
  around_hooks.reverse.inject(wrapped_example) do |wrapper, hook|
178
178
  def wrapper.run; call; end
179
- lambda { example_group_instance.instance_exec(wrapper, &hook) }
179
+ lambda { example_group_instance.instance_eval_with_args(wrapper, &hook) }
180
180
  end
181
181
  end
182
182
 
@@ -227,10 +227,6 @@ module RSpec
227
227
  end.all?
228
228
  end
229
229
 
230
- def self.to_s
231
- self == RSpec::Core::ExampleGroup ? 'RSpec::Core::ExampleGroup' : name
232
- end
233
-
234
230
  def self.all_apply?(filters)
235
231
  metadata.all_apply?(filters)
236
232
  end
@@ -258,7 +254,7 @@ module RSpec
258
254
  end
259
255
 
260
256
  def described_class
261
- self.class.describes
257
+ self.class.described_class
262
258
  end
263
259
 
264
260
  def instance_eval_with_rescue(&hook)
@@ -268,19 +264,6 @@ module RSpec
268
264
  example.set_exception(e)
269
265
  end
270
266
  end
271
-
272
- private
273
-
274
- def self.extended_modules #:nodoc:
275
- @extended_modules ||= ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ]
276
- end
277
-
278
- def self.mixins
279
- @mixins ||= {
280
- :include => included_modules,
281
- :extend => extended_modules
282
- }
283
- end
284
267
  end
285
268
  end
286
269
  end