rspec-core 2.4.0 → 2.5.0

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 (78) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +9 -4
  3. data/Guardfile +3 -3
  4. data/README.md +1 -1
  5. data/features/.nav +7 -2
  6. data/features/{README.markdown → Autotest.md} +17 -20
  7. data/features/Changelog.md +57 -2
  8. data/features/README.md +17 -0
  9. data/features/Upgrade.md +8 -66
  10. data/features/command_line/configure.feature +2 -2
  11. data/features/command_line/example_name_option.feature +10 -10
  12. data/features/command_line/exit_status.feature +4 -4
  13. data/features/command_line/line_number_appended_to_path.feature +11 -11
  14. data/features/command_line/line_number_option.feature +9 -9
  15. data/features/command_line/tag.feature +9 -9
  16. data/features/configuration/custom_settings.feature +3 -3
  17. data/features/configuration/fail_fast.feature +3 -3
  18. data/features/configuration/read_options_from_file.feature +4 -4
  19. data/features/example_groups/shared_example_group.feature +4 -4
  20. data/features/expectation_framework_integration/configure_expectation_framework.feature +8 -9
  21. data/features/filtering/exclusion_filters.feature +1 -1
  22. data/features/filtering/run_all_when_everything_filtered.feature +1 -1
  23. data/features/formatters/custom_formatter.feature +17 -13
  24. data/features/helper_methods/arbitrary_methods.feature +40 -0
  25. data/features/helper_methods/let.feature +50 -0
  26. data/features/hooks/before_and_after_hooks.feature +10 -10
  27. data/features/hooks/filtering.feature +37 -20
  28. data/features/metadata/described_class.feature +1 -1
  29. data/features/mock_framework_integration/use_flexmock.feature +1 -1
  30. data/features/mock_framework_integration/use_mocha.feature +1 -1
  31. data/features/mock_framework_integration/use_rr.feature +1 -1
  32. data/features/mock_framework_integration/use_rspec.feature +1 -1
  33. data/features/spec_files/arbitrary_file_suffix.feature +1 -1
  34. data/features/step_definitions/additional_cli_steps.rb +1 -1
  35. data/features/subject/attribute_of_subject.feature +2 -2
  36. data/features/subject/explicit_subject.feature +5 -5
  37. data/features/subject/implicit_receiver.feature +2 -2
  38. data/features/subject/implicit_subject.feature +2 -2
  39. data/lib/autotest/rspec2.rb +63 -13
  40. data/lib/rspec/core/configuration.rb +0 -1
  41. data/lib/rspec/core/configuration_options.rb +15 -12
  42. data/lib/rspec/core/example.rb +14 -6
  43. data/lib/rspec/core/example_group.rb +5 -4
  44. data/lib/rspec/core/formatters/base_formatter.rb +1 -1
  45. data/lib/rspec/core/formatters/documentation_formatter.rb +1 -1
  46. data/lib/rspec/core/formatters/html_formatter.rb +131 -32
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
  48. data/lib/rspec/core/hooks.rb +16 -1
  49. data/lib/rspec/core/option_parser.rb +6 -6
  50. data/lib/rspec/core/rake_task.rb +1 -1
  51. data/lib/rspec/core/subject.rb +7 -7
  52. data/lib/rspec/core/version.rb +1 -1
  53. data/rspec-core.gemspec +0 -12
  54. data/script/FullBuildRakeFile +63 -0
  55. data/script/cucumber +1 -0
  56. data/script/full_build +1 -0
  57. data/script/spec +1 -0
  58. data/spec/autotest/failed_results_re_spec.rb +22 -5
  59. data/spec/autotest/rspec_spec.rb +132 -16
  60. data/spec/rspec/core/configuration_options_spec.rb +38 -6
  61. data/spec/rspec/core/example_group_spec.rb +15 -64
  62. data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -0
  63. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +150 -48
  64. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +151 -49
  65. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +150 -48
  66. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +150 -48
  67. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +150 -48
  68. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +150 -48
  69. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +151 -49
  70. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +150 -48
  71. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +150 -48
  72. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +150 -48
  73. data/spec/rspec/core/hooks_filtering_spec.rb +49 -0
  74. data/spec/rspec/core/rake_task_spec.rb +3 -3
  75. data/spec/rspec/core/subject_spec.rb +81 -0
  76. metadata +20 -22
  77. data/History.markdown +0 -186
  78. data/Upgrade.markdown +0 -345
@@ -1,11 +1,11 @@
1
- Feature: Global Hook Filtering
1
+ Feature: filters
2
2
 
3
- Before/After/Around hooks defined in the RSpec configuration block
4
- can be filtered using metadata. Arbitrary metadata can be applied
5
- to an example or example group, and used to make a hook only apply
6
- to examples with the given metadata.
3
+ `before`/`after`/`around` hooks defined in the RSpec configuration block can
4
+ be filtered using metadata. Arbitrary metadata can be applied to an example
5
+ or example group, and used to make a hook only apply to examples with the
6
+ given metadata.
7
7
 
8
- Scenario: Filter before(:each) hooks using arbitrary metadata
8
+ Scenario: filter `before(:each)` hooks using arbitrary metadata
9
9
  Given a file named "filter_before_each_hooks_spec.rb" with:
10
10
  """
11
11
  RSpec.configure do |config|
@@ -23,8 +23,7 @@ Feature: Global Hook Filtering
23
23
  end
24
24
  """
25
25
  When I run "rspec filter_before_each_hooks_spec.rb --format documentation"
26
- Then the output should contain "4 examples, 0 failures"
27
- And the output should contain:
26
+ Then the output should contain:
28
27
  """
29
28
  group 1
30
29
  example 1
@@ -38,7 +37,7 @@ Feature: Global Hook Filtering
38
37
  example 2
39
38
  """
40
39
 
41
- Scenario: Filter after(:each) hooks using arbitrary metadata
40
+ Scenario: filter `after(:each)` hooks using arbitrary metadata
42
41
  Given a file named "filter_after_each_hooks_spec.rb" with:
43
42
  """
44
43
  RSpec.configure do |config|
@@ -56,8 +55,7 @@ Feature: Global Hook Filtering
56
55
  end
57
56
  """
58
57
  When I run "rspec filter_after_each_hooks_spec.rb --format documentation"
59
- Then the output should contain "4 examples, 0 failures"
60
- And the output should contain:
58
+ Then the output should contain:
61
59
  """
62
60
  group 1
63
61
  example 1
@@ -71,7 +69,7 @@ Feature: Global Hook Filtering
71
69
  example 2
72
70
  """
73
71
 
74
- Scenario: Filter around(:each) hooks using arbitrary metadata
72
+ Scenario: filter around(:each) hooks using arbitrary metadata
75
73
  Given a file named "filter_around_each_hooks_spec.rb" with:
76
74
  """
77
75
  RSpec.configure do |config|
@@ -93,8 +91,7 @@ Feature: Global Hook Filtering
93
91
  end
94
92
  """
95
93
  When I run "rspec filter_around_each_hooks_spec.rb --format documentation"
96
- Then the output should contain "4 examples, 0 failures"
97
- And the output should contain:
94
+ Then the output should contain:
98
95
  """
99
96
  group 1
100
97
  example 1
@@ -111,7 +108,7 @@ Feature: Global Hook Filtering
111
108
  example 2
112
109
  """
113
110
 
114
- Scenario: Filter before(:all) hooks using arbitrary metadata
111
+ Scenario: filter before(:all) hooks using arbitrary metadata
115
112
  Given a file named "filter_before_all_hooks_spec.rb" with:
116
113
  """
117
114
  RSpec.configure do |config|
@@ -127,10 +124,15 @@ Feature: Global Hook Filtering
127
124
  it("example 1") { }
128
125
  it("example 2") { }
129
126
  end
127
+
128
+ describe "group 3" do
129
+ describe "subgroup 1", :foo => :bar do
130
+ it("example 1") { }
131
+ end
132
+ end
130
133
  """
131
134
  When I run "rspec filter_before_all_hooks_spec.rb --format documentation"
132
- Then the output should contain "4 examples, 0 failures"
133
- And the output should contain:
135
+ Then the output should contain:
134
136
  """
135
137
  group 1
136
138
  example 1
@@ -140,9 +142,14 @@ Feature: Global Hook Filtering
140
142
  In hook
141
143
  example 1
142
144
  example 2
145
+
146
+ group 3
147
+ subgroup 1
148
+ In hook
149
+ example 1
143
150
  """
144
151
 
145
- Scenario: Filter after(:all) hooks using arbitrary metadata
152
+ Scenario: filter after(:all) hooks using arbitrary metadata
146
153
  Given a file named "filter_after_all_hooks_spec.rb" with:
147
154
  """
148
155
  RSpec.configure do |config|
@@ -158,10 +165,15 @@ Feature: Global Hook Filtering
158
165
  it("example 1") { }
159
166
  it("example 2") { }
160
167
  end
168
+
169
+ describe "group 3" do
170
+ describe "subgroup 1", :foo => :bar do
171
+ it("example 1") { }
172
+ end
173
+ end
161
174
  """
162
175
  When I run "rspec filter_after_all_hooks_spec.rb --format documentation"
163
- Then the output should contain "4 examples, 0 failures"
164
- And the output should contain:
176
+ Then the output should contain:
165
177
  """
166
178
  group 1
167
179
  example 1
@@ -171,4 +183,9 @@ Feature: Global Hook Filtering
171
183
  example 1
172
184
  example 2
173
185
  In hook
186
+
187
+ group 3
188
+ subgroup 1
189
+ example 1
190
+ In hook
174
191
  """
@@ -13,5 +13,5 @@ Feature: described class
13
13
  end
14
14
  """
15
15
  When I run "rspec ./spec/example_spec.rb"
16
- Then the output should contain "1 example, 0 failures"
16
+ Then the examples should all pass
17
17
 
@@ -19,5 +19,5 @@ Feature: mock with flexmock
19
19
  end
20
20
  """
21
21
  When I run "rspec ./flexmock_example_spec.rb"
22
- Then the output should contain "1 example, 0 failures"
22
+ Then the examples should all pass
23
23
  And the exit status should be 0
@@ -19,5 +19,5 @@ Feature: mock with mocha
19
19
  end
20
20
  """
21
21
  When I run "rspec ./mocha_example_spec.rb"
22
- Then the output should contain "1 example, 0 failures"
22
+ Then the examples should all pass
23
23
  And the exit status should be 0
@@ -19,5 +19,5 @@ Feature: mock with rr
19
19
  end
20
20
  """
21
21
  When I run "rspec ./rr_example_spec.rb"
22
- Then the output should contain "1 example, 0 failures"
22
+ Then the examples should all pass
23
23
  And the exit status should be 0
@@ -19,5 +19,5 @@ Feature: mock with rspec
19
19
  end
20
20
  """
21
21
  When I run "rspec ./rspec_example_spec.rb"
22
- Then the output should contain "1 example, 0 failures"
22
+ Then the examples should all pass
23
23
  And the exit status should be 0
@@ -10,4 +10,4 @@ Feature: arbitrary file suffix
10
10
  end
11
11
  """
12
12
  When I run "rspec a.spec"
13
- Then the output should contain "1 example, 0 failures"
13
+ Then the examples should all pass
@@ -10,7 +10,7 @@ Then /^the output should not contain any of these:$/ do |table|
10
10
  end
11
11
  end
12
12
 
13
- Then /^the example(s)? should( all)? pass$/ do |*|
13
+ Then /^the example(?:s)? should(?: all)? pass$/ do
14
14
  Then %q{the output should contain "0 failures"}
15
15
  Then %q{the exit status should be 0}
16
16
  end
@@ -82,7 +82,7 @@ Feature: attribute of subject
82
82
  end
83
83
  """
84
84
  When I run "rspec example_spec.rb"
85
- Then the output should contain "1 example, 0 failures"
85
+ Then the examples should all pass
86
86
 
87
87
  Scenario: specify value for key in a hash
88
88
  Given a file named "example_spec.rb" with:
@@ -99,4 +99,4 @@ Feature: attribute of subject
99
99
  end
100
100
  """
101
101
  When I run "rspec example_spec.rb"
102
- Then the output should contain "2 examples, 0 failures"
102
+ Then the examples should all pass
@@ -14,7 +14,7 @@ Feature: explicit subject
14
14
  end
15
15
  """
16
16
  When I run "rspec top_level_subject_spec.rb"
17
- Then the output should contain "1 example, 0 failures"
17
+ Then the examples should all pass
18
18
 
19
19
  Scenario: subject in a nested group
20
20
  Given a file named "nested_subject_spec.rb" with:
@@ -29,7 +29,7 @@ Feature: explicit subject
29
29
  end
30
30
  """
31
31
  When I run "rspec nested_subject_spec.rb"
32
- Then the output should contain "1 example, 0 failures"
32
+ Then the examples should all pass
33
33
 
34
34
  Scenario: access subject from before block
35
35
  Given a file named "top_level_subject_spec.rb" with:
@@ -43,7 +43,7 @@ Feature: explicit subject
43
43
  end
44
44
  """
45
45
  When I run "rspec top_level_subject_spec.rb"
46
- Then the output should contain "1 example, 0 failures"
46
+ Then the examples should all pass
47
47
 
48
48
  Scenario: invoke helper method from subject block
49
49
  Given a file named "helper_subject_spec.rb" with:
@@ -59,7 +59,7 @@ Feature: explicit subject
59
59
  end
60
60
  """
61
61
  When I run "rspec helper_subject_spec.rb"
62
- Then the output should contain "1 example, 0 failures"
62
+ Then the examples should all pass
63
63
 
64
64
  Scenario: subject block is invoked at most once per example
65
65
  Given a file named "nil_subject_spec.rb" with:
@@ -75,4 +75,4 @@ Feature: explicit subject
75
75
  end
76
76
  """
77
77
  When I run "rspec nil_subject_spec.rb"
78
- Then the output should contain "1 example, 0 failures"
78
+ Then the examples should all pass
@@ -13,7 +13,7 @@ Feature: implicit receiver
13
13
  end
14
14
  """
15
15
  When I run "rspec example_spec.rb"
16
- Then the output should contain "1 example, 0 failures"
16
+ Then the examples should all pass
17
17
 
18
18
  Scenario: explicit subject
19
19
  Given a file named "example_spec.rb" with:
@@ -26,4 +26,4 @@ Feature: implicit receiver
26
26
  end
27
27
  """
28
28
  When I run "rspec example_spec.rb"
29
- Then the output should contain "1 example, 0 failures"
29
+ Then the examples should all pass
@@ -13,7 +13,7 @@ Feature: implicit subject
13
13
  end
14
14
  """
15
15
  When I run "rspec ./top_level_subject_spec.rb"
16
- Then the output should contain "1 example, 0 failures"
16
+ Then the examples should all pass
17
17
 
18
18
  Scenario: subject in a nested group
19
19
  Given a file named "nested_subject_spec.rb" with:
@@ -27,4 +27,4 @@ Feature: implicit subject
27
27
  end
28
28
  """
29
29
  When I run "rspec nested_subject_spec.rb"
30
- Then the output should contain "1 example, 0 failures"
30
+ Then the examples should all pass
@@ -1,19 +1,25 @@
1
1
  require 'autotest'
2
+ require 'rspec/core/deprecation'
2
3
 
3
4
  class RSpecCommandError < StandardError; end
4
5
 
5
6
  class Autotest::Rspec2 < Autotest
6
7
 
7
- SPEC_PROGRAM = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec'))
8
+ attr_reader :cl_args, :skip_bundler
9
+ alias_method :skip_bundler?, :skip_bundler
10
+
11
+ SPEC_PROGRAM = File.expand_path('../../../bin/rspec', __FILE__)
8
12
 
9
13
  def initialize
10
- super
14
+ super()
15
+ @cl_args = ARGV.dup << "--tty"
16
+ @skip_bundler = @cl_args.delete("--skip-bundler")
11
17
  clear_mappings
12
18
  setup_rspec_project_mappings
13
19
 
14
20
  # Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
15
21
  # Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
16
- self.failed_results_re = /^\s*\d+\).*\n\s+Failure.*(\n\s+#\s(.*)?:\d+(?::.*)?)+$/m
22
+ self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?(?:\e\[\d*m)?)+$/m
17
23
  self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
18
24
  end
19
25
 
@@ -40,16 +46,9 @@ class Autotest::Rspec2 < Autotest
40
46
  end
41
47
 
42
48
  def make_test_cmd(files_to_test)
49
+ warn_about_bundler if rspec_wants_bundler? && !autotest_wants_bundler?
43
50
  files_to_test.empty? ? '' :
44
- "#{bundle_exec}#{ruby} #{require_rubygems}-S #{SPEC_PROGRAM} --tty #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
45
- end
46
-
47
- def bundle_exec
48
- using_bundler? ? "bundle exec " : ""
49
- end
50
-
51
- def require_rubygems
52
- using_bundler? ? "" : defined?(:Gem) ? "-rrubygems " : " "
51
+ "#{prefix}#{ruby}#{suffix} -S #{SPEC_PROGRAM} #{cl_args.join(' ')} #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
53
52
  end
54
53
 
55
54
  def normalize(files_to_test)
@@ -59,8 +58,59 @@ class Autotest::Rspec2 < Autotest
59
58
  end
60
59
  end
61
60
 
61
+ def warn_about_bundler
62
+ RSpec.warn_deprecation <<-WARNING
63
+
64
+ ****************************************************************************
65
+ DEPRECATION WARNING: you are using deprecated behaviour that will be removed
66
+ from a future version of RSpec.
67
+
68
+ RSpec's autotest extension is relying on the presence of a Gemfile in the
69
+ project root directory to generate a command including 'bundle exec'.
70
+
71
+ You have two options to suppress this message:
72
+
73
+ If you want to include 'bundle exec' in the command, add a .autotest file to
74
+ the project root with the following content:
75
+
76
+ require 'autotest/bundler'
77
+
78
+ If you want to _not_include 'bundle exec' in the command, pass --skip-bundler
79
+ to autotest as an extra argument, like this:
80
+
81
+ autotest -- --skip-bundler
82
+ *****************************************************************
83
+ WARNING
84
+ end
85
+
86
+ alias_method :autotest_prefix, :prefix
87
+
88
+ def rspec_prefix
89
+ (rspec_wants_bundler? && !autotest_wants_bundler?) ? "bundle exec " : ""
90
+ end
91
+
92
+ def prefix
93
+ skip_bundler? ? "#{rspec_prefix}#{autotest_prefix}".gsub("bundle exec","") : "#{rspec_prefix}#{autotest_prefix}"
94
+ end
95
+
96
+ def autotest_wants_bundler?
97
+ autotest_prefix =~ /bundle exec/
98
+ end
99
+
100
+ def suffix
101
+ using_bundler? ? "" : defined?(:Gem) ? " -rrubygems" : ""
102
+ end
103
+
104
+ def rspec_wants_bundler?
105
+ gemfile? && !skip_bundler?
106
+ end
107
+
62
108
  def using_bundler?
63
- File.exists?('./Gemfile')
109
+ rspec_wants_bundler? || autotest_wants_bundler?
110
+ end
111
+
112
+ def gemfile?
113
+ File.exist?('./Gemfile')
64
114
  end
65
115
 
66
116
  end
@@ -368,7 +368,6 @@ EOM
368
368
 
369
369
  include_or_extend_modules.each do |include_or_extend, mod, filters|
370
370
  next unless filters.empty? || group.apply?(:any?, filters)
371
- next if self.class < mod
372
371
  group.send(include_or_extend, mod)
373
372
  end
374
373
  end
@@ -31,20 +31,23 @@ module RSpec
31
31
 
32
32
  def drb_argv
33
33
  argv = []
34
- argv << "--color" if options[:color_enabled]
35
- argv << "--profile" if options[:profile_examples]
36
- argv << "--backtrace" if options[:full_backtrace]
37
- argv << "--tty" if options[:tty]
38
- argv << "--fail-fast" if options[:fail_fast]
34
+ argv << "--color" if options[:color_enabled]
35
+ argv << "--profile" if options[:profile_examples]
36
+ argv << "--backtrace" if options[:full_backtrace]
37
+ argv << "--tty" if options[:tty]
38
+ argv << "--fail-fast" if options[:fail_fast]
39
39
  argv << "--line_number" << options[:line_number] if options[:line_number]
40
- argv << "--options" << options[:custom_options_file] if options[:custom_options_file]
40
+ argv << "--options" << options[:custom_options_file] if options[:custom_options_file]
41
41
  argv << "--example" << options[:full_description].source if options[:full_description]
42
+ if options[:filter]
43
+ options[:filter].each_pair do |k, v|
44
+ argv << "--tag" << k.to_s
45
+ end
46
+ end
42
47
  if options[:formatters]
43
48
  options[:formatters].each do |pair|
44
- argv << "--format" << pair.shift
45
- unless pair.empty?
46
- argv << "--out" << pair.shift
47
- end
49
+ argv << "--format" << pair[0]
50
+ argv << "--out" << pair[1] if pair[1]
48
51
  end
49
52
  end
50
53
  (options[:libs] || []).each do |path|
@@ -65,8 +68,8 @@ module RSpec
65
68
  options_to_merge << global_options
66
69
  options_to_merge << local_options
67
70
  end
68
- options_to_merge << env_options
69
71
  options_to_merge << command_line_options
72
+ options_to_merge << env_options
70
73
 
71
74
  options_to_merge.inject do |merged, options|
72
75
  merged.merge(options)
@@ -109,7 +112,7 @@ module RSpec
109
112
  config_string = options_file_as_erb_string(path)
110
113
  config_string.split(/\n+/).map {|l| l.split}.flatten
111
114
  end
112
-
115
+
113
116
  def options_file_as_erb_string(path)
114
117
  require 'erb'
115
118
  ERB.new(IO.read(path)).result(binding)
@@ -75,12 +75,20 @@ module RSpec
75
75
  finish(reporter)
76
76
  end
77
77
 
78
- class Procsy < Proc
78
+ def self.procsy(metadata, &block)
79
+ Proc.new(&block).extend(Procsy).with(metadata)
80
+ end
81
+
82
+ module Procsy
79
83
  attr_reader :metadata
80
- alias_method :run, :call
81
- def initialize(metadata, &block)
84
+
85
+ def self.extended(object)
86
+ def object.run; call; end
87
+ end
88
+
89
+ def with(metadata)
82
90
  @metadata = metadata
83
- super(&block)
91
+ self
84
92
  end
85
93
  end
86
94
 
@@ -93,11 +101,11 @@ module RSpec
93
101
  end
94
102
  end
95
103
 
96
- def with_around_hooks
104
+ def with_around_hooks(&block)
97
105
  if around_hooks.empty?
98
106
  yield
99
107
  else
100
- @example_group_class.eval_around_eachs(self, Procsy.new(metadata)).call
108
+ @example_group_class.eval_around_eachs(self, Example.procsy(metadata, &block)).call
101
109
  end
102
110
  end
103
111