rspec-core 2.0.0.beta.12 → 2.0.0.beta.13

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 (38) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +14 -0
  3. data/Rakefile +15 -12
  4. data/VERSION +1 -1
  5. data/features/command_line/example_name_option.feature +17 -3
  6. data/features/command_line/exit_status.feature +49 -0
  7. data/features/hooks/before_and_after_hooks.feature +51 -19
  8. data/features/hooks/halt.feature +1 -1
  9. data/features/support/env.rb +5 -3
  10. data/lib/rspec/core/command_line.rb +14 -5
  11. data/lib/rspec/core/configuration.rb +14 -24
  12. data/lib/rspec/core/configuration_options.rb +13 -8
  13. data/lib/rspec/core/drb_command_line.rb +2 -3
  14. data/lib/rspec/core/example.rb +5 -5
  15. data/lib/rspec/core/example_group.rb +23 -25
  16. data/lib/rspec/core/formatters/base_text_formatter.rb +13 -4
  17. data/lib/rspec/core/hooks.rb +57 -24
  18. data/lib/rspec/core/metadata.rb +1 -1
  19. data/lib/rspec/core/pending.rb +3 -3
  20. data/lib/rspec/core/rake_task.rb +48 -11
  21. data/lib/rspec/core/runner.rb +19 -8
  22. data/lib/rspec/core/subject.rb +3 -3
  23. data/lib/rspec/core/world.rb +3 -7
  24. data/rspec-core.gemspec +16 -12
  25. data/spec/rspec/core/command_line_spec.rb +72 -0
  26. data/spec/rspec/core/configuration_options_spec.rb +12 -3
  27. data/spec/rspec/core/configuration_spec.rb +6 -1
  28. data/spec/rspec/core/deprecations_spec.rb +19 -0
  29. data/spec/rspec/core/drb_command_line_spec.rb +1 -1
  30. data/spec/rspec/core/example_group_spec.rb +120 -12
  31. data/spec/rspec/core/example_spec.rb +27 -17
  32. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +23 -0
  33. data/spec/rspec/core/metadata_spec.rb +32 -0
  34. data/spec/rspec/core/runner_spec.rb +2 -1
  35. data/spec/rspec/core/shared_example_group_spec.rb +1 -1
  36. data/spec/spec_helper.rb +49 -51
  37. data/specs.watchr +1 -1
  38. metadata +31 -27
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg
7
7
  tmp
8
8
  tags
9
9
  rerun.txt
10
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ gem "bundler"
2
+ gem "rake"
3
+ gem "jeweler"
4
+ gem "cucumber"
5
+ gem "aruba"
6
+ gem "autotest"
7
+ gem "rcov"
8
+ gem "mocha"
9
+ gem "rr"
10
+ gem "flexmock"
11
+ gem "rspec-core", :path => "."
12
+ gem "rspec-expectations", :path => "../rspec-expectations"
13
+ gem "rspec-mocks", :path => "../rspec-mocks"
14
+ gem "ruby-debug"
data/Rakefile CHANGED
@@ -1,29 +1,32 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
1
4
  gem "jeweler", ">= 1.4.0"
2
- require 'rake'
3
- require 'yaml'
5
+ require "rake"
6
+ require "yaml"
4
7
 
5
- $:.unshift File.expand_path('../lib', __FILE__)
8
+ $:.unshift File.expand_path("../lib", __FILE__)
6
9
 
7
- require 'rake/rdoctask'
8
- require 'rspec/core/rake_task'
9
- require 'rspec/core/version'
10
- require 'cucumber/rake/task'
10
+ require "rake/rdoctask"
11
+ require "rspec/core/rake_task"
12
+ require "rspec/core/version"
13
+ require "cucumber/rake/task"
11
14
 
12
15
  begin
13
- require 'jeweler'
16
+ require "jeweler"
14
17
  Jeweler::Tasks.new do |gem|
15
18
  gem.name = "rspec-core"
16
19
  gem.version = RSpec::Core::Version::STRING
17
20
  gem.summary = "rspec-core-#{RSpec::Core::Version::STRING}"
18
- gem.description = 'RSpec runner and example group classes'
21
+ gem.description = "RSpec runner and example groups"
19
22
  gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
20
- gem.homepage = "http://github.com/rspec/core"
23
+ gem.homepage = "http://github.com/rspec/rspec-core"
21
24
  gem.authors = ["Chad Humphries", "David Chelimsky"]
22
25
  gem.rubyforge_project = "rspec"
23
26
  gem.add_development_dependency "rspec-expectations", ">= #{RSpec::Core::Version::STRING}"
24
27
  gem.add_development_dependency "rspec-mocks", ">= #{RSpec::Core::Version::STRING}"
25
- gem.add_development_dependency('cucumber', '>= 0.5.3')
26
- gem.add_development_dependency('autotest', '>= 4.2.9')
28
+ gem.add_development_dependency "cucumber", ">= 0.5.3"
29
+ gem.add_development_dependency "autotest", ">= 4.2.9"
27
30
  gem.post_install_message = <<-EOM
28
31
  #{"*"*50}
29
32
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.12
1
+ 2.0.0.beta.13
@@ -24,6 +24,16 @@ Feature: example name option
24
24
  it "second example in second group" do; end
25
25
  end
26
26
  """
27
+ Given a file named "third_spec.rb" with:
28
+ """
29
+ describe "third group" do
30
+ it "first example in third group" do; end
31
+ context "nested group" do
32
+ it "first example in nested group" do; end
33
+ it "second example in nested group" do; end
34
+ end
35
+ end
36
+ """
27
37
 
28
38
  Scenario: no matches
29
39
  When I run "rspec . --example nothing_like_this"
@@ -31,11 +41,11 @@ Feature: example name option
31
41
 
32
42
  Scenario: match on one word
33
43
  When I run "rspec . --example example"
34
- Then I should see "4 examples, 0 failures"
44
+ Then I should see "7 examples, 0 failures"
35
45
 
36
- Scenario: one match in each file
46
+ Scenario: one match in each context
37
47
  When I run "rspec . --example 'first example'"
38
- Then I should see "2 examples, 0 failures"
48
+ Then I should see "4 examples, 0 failures"
39
49
 
40
50
  Scenario: one match in one file using just the example name
41
51
  When I run "rspec . --example 'first example in first group'"
@@ -56,3 +66,7 @@ Feature: example name option
56
66
  Scenario: one match in one file with group name
57
67
  When I run "rspec . --example 'second group first example'"
58
68
  Then I should see "1 example, 0 failures"
69
+
70
+ Scenario: all examples in one group including examples in nested groups
71
+ When I run "rspec . --example 'third group'"
72
+ Then I should see "3 examples, 0 failures"
@@ -0,0 +1,49 @@
1
+ Feature: exit status
2
+ In order to fail the build when it should,
3
+ the spec CLI exits with an appropriate exit status
4
+
5
+ Scenario: exit with 0 when all examples pass
6
+ Given a file named "ok_spec.rb" with:
7
+ """
8
+ describe "ok" do
9
+ it "passes" do
10
+ end
11
+ end
12
+ """
13
+ When I run "rspec ok_spec.rb"
14
+ Then it should pass with:
15
+ """
16
+ 1 example, 0 failures
17
+ """
18
+
19
+ Scenario: exit with 1 when one example fails
20
+ Given a file named "ko_spec.rb" with:
21
+ """
22
+ describe "KO" do
23
+ it "fails" do
24
+ raise "KO"
25
+ end
26
+ end
27
+ """
28
+ When I run "rspec ko_spec.rb"
29
+ Then it should fail with:
30
+ """
31
+ 1 example, 1 failure
32
+ """
33
+
34
+ Scenario: exit with 1 when a nested examples fails
35
+ Given a file named "nested_ko_spec.rb" with:
36
+ """
37
+ describe "KO" do
38
+ describe "nested" do
39
+ it "fails" do
40
+ raise "KO"
41
+ end
42
+ end
43
+ end
44
+ """
45
+ When I run "rspec nested_ko_spec.rb"
46
+ Then it should fail with:
47
+ """
48
+ 1 example, 1 failure
49
+ """
@@ -14,10 +14,12 @@ Feature: before and after hooks
14
14
  after(:all) blocks are run once after all of the examples in a group
15
15
 
16
16
  Before and after blocks are called in the following order:
17
+ before suite
17
18
  before all
18
19
  before each
19
- after each
20
- after all
20
+ after each
21
+ after all
22
+ after suite
21
23
 
22
24
  Before and after blocks can be defined in the example groups to which they
23
25
  apply or in a configuration. When defined in a configuration, they can be
@@ -155,6 +157,53 @@ Feature: before and after hooks
155
157
  When I run "rspec ./ensure_block_order_spec.rb"
156
158
  Then I should see matching /before all\nbefore each\nafter each\n.after all/
157
159
 
160
+ Scenario: before/after blocks defined in config are run in order
161
+ Given a file named "configuration_spec.rb" with:
162
+ """
163
+ require "rspec/expectations"
164
+
165
+ RSpec.configure do |config|
166
+ config.before(:suite) do
167
+ puts "before suite"
168
+ end
169
+
170
+ config.before(:all) do
171
+ puts "before all"
172
+ end
173
+
174
+ config.before(:each) do
175
+ puts "before each"
176
+ end
177
+
178
+ config.after(:each) do
179
+ puts "after each"
180
+ end
181
+
182
+ config.after(:all) do
183
+ puts "after all"
184
+ end
185
+
186
+ config.after(:suite) do
187
+ puts "after suite"
188
+ end
189
+ end
190
+
191
+ describe "ignore" do
192
+ example "ignore" do
193
+ end
194
+ end
195
+ """
196
+ When I run "rspec configuration_spec.rb"
197
+ Then I should see matching:
198
+ """
199
+ before suite
200
+ before all
201
+ before each
202
+ after each
203
+ .after all
204
+ after suite
205
+ """
206
+
158
207
  Scenario: before/after all blocks are run once
159
208
  Given a file named "before_and_after_all_spec.rb" with:
160
209
  """
@@ -278,20 +327,3 @@ Feature: before and after hooks
278
327
  When I run "rspec ./error_in_before_each_spec.rb"
279
328
  Then I should see "1 example, 1 failure"
280
329
  And I should see "this error"
281
-
282
- @wip
283
- Scenario: exception in before(:all) is captured and reported as failure
284
- Given a file named "error_in_before_all_spec.rb" with:
285
- """
286
- describe "error in before(:all)" do
287
- before(:all) do
288
- raise "this error"
289
- end
290
-
291
- it "is reported as failure" do
292
- end
293
- end
294
- """
295
- When I run "rspec ./error_in_before_all_spec.rb"
296
- Then I should see "1 example, 1 failure"
297
- And I should see "this error"
@@ -10,7 +10,7 @@ Feature: halt
10
10
  """
11
11
  RSpec.configure do |c|
12
12
  c.after(:each) do
13
- running_example.halt(:group, :status => 'failed')
13
+ example.halt(:group, :status => 'failed')
14
14
  end
15
15
  end
16
16
  describe "something" do
@@ -1,11 +1,13 @@
1
- $LOAD_PATH.unshift File.expand_path("../../../../rspec-expectations/lib", __FILE__)
2
- require 'rspec/expectations'
1
+ require "bundler"
2
+ Bundler.setup
3
+
3
4
  require 'aruba'
5
+ require 'rspec/expectations'
4
6
 
5
7
  module ArubaOverrides
6
8
  def detect_ruby_script(cmd)
7
9
  if cmd =~ /^rspec /
8
- "ruby -I../../lib -S ../../bin/#{cmd}"
10
+ "bundle exec ../../bin/#{cmd}"
9
11
  else
10
12
  super(cmd)
11
13
  end
@@ -1,9 +1,13 @@
1
1
  module RSpec
2
2
  module Core
3
3
  class CommandLine
4
- def initialize(argv)
5
- @options = RSpec::Core::ConfigurationOptions.new(argv)
6
- @options.parse_options
4
+ def initialize(args_or_options)
5
+ if RSpec::Core::ConfigurationOptions === args_or_options
6
+ @options = args_or_options
7
+ else
8
+ @options = RSpec::Core::ConfigurationOptions.new(args_or_options)
9
+ @options.parse_options
10
+ end
7
11
  @options.configure(configuration)
8
12
  configuration.require_files_to_run
9
13
  configuration.configure_mock_framework
@@ -15,9 +19,14 @@ module RSpec
15
19
  world.announce_inclusion_filter
16
20
 
17
21
  configuration.reporter.report(example_count) do |reporter|
18
- example_groups.run_examples(reporter)
22
+ begin
23
+ configuration.run_hook(:before, :suite)
24
+ example_groups.run_examples(reporter)
25
+ ensure
26
+ configuration.run_hook(:after, :suite)
27
+ end
19
28
  end
20
-
29
+
21
30
  example_groups.success?
22
31
  end
23
32
 
@@ -1,6 +1,10 @@
1
+ require "rbconfig"
2
+
1
3
  module RSpec
2
4
  module Core
3
5
  class Configuration
6
+ include RSpec::Core::Hooks
7
+
4
8
  def self.add_setting(name, opts={})
5
9
  if opts[:alias]
6
10
  alias_method name, opts[:alias]
@@ -16,6 +20,7 @@ module RSpec
16
20
  add_setting :error_stream
17
21
  add_setting :output_stream
18
22
  add_setting :output, :alias => :output_stream
23
+ add_setting :drb
19
24
  add_setting :drb_port
20
25
  add_setting :color_enabled
21
26
  add_setting :profile_examples
@@ -82,13 +87,6 @@ module RSpec
82
87
  output_stream.puts(message)
83
88
  end
84
89
 
85
- def hooks
86
- @hooks ||= {
87
- :before => { :each => [], :all => [], :suite => [] },
88
- :after => { :each => [], :all => [], :suite => [] }
89
- }
90
- end
91
-
92
90
  def settings
93
91
  @settings ||= {}
94
92
  end
@@ -123,7 +121,7 @@ module RSpec
123
121
  def color_enabled=(bool)
124
122
  return unless bool
125
123
  settings[:color_enabled] = true
126
- if bool && Config::CONFIG['host_os'] =~ /mswin|mingw/
124
+ if bool && ::Config::CONFIG['host_os'] =~ /mswin|mingw/
127
125
  orig_output_stream = settings[:output_stream]
128
126
  begin
129
127
  require 'Win32/Console/ANSI'
@@ -171,7 +169,9 @@ EOM
171
169
  end
172
170
 
173
171
  def formatter=(formatter_to_use)
174
- if formatter_to_use.is_a?(Class)
172
+ if string_const?(formatter_to_use) && Object.const_defined?(formatter_to_use)
173
+ formatter_class = Object.const_get(formatter_to_use)
174
+ elsif formatter_to_use.is_a?(Class)
175
175
  formatter_class = formatter_to_use
176
176
  else
177
177
  formatter_class = case formatter_to_use.to_s
@@ -185,7 +185,11 @@ EOM
185
185
  end
186
186
  self.formatter_class = formatter_class
187
187
  end
188
-
188
+
189
+ def string_const?(str)
190
+ str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
191
+ end
192
+
189
193
  def formatter
190
194
  @formatter ||= formatter_class.new(output)
191
195
  end
@@ -237,20 +241,6 @@ EOM
237
241
  end
238
242
  end
239
243
 
240
- def before(each_or_all=:each, options={}, &block)
241
- hooks[:before][each_or_all] << [options, block]
242
- end
243
-
244
- def after(each_or_all=:each, options={}, &block)
245
- hooks[:after][each_or_all] << [options, block]
246
- end
247
-
248
- def find_hook(hook, each_or_all, group)
249
- hooks[hook][each_or_all].select do |filters, block|
250
- group.all_apply?(filters)
251
- end.map { |filters, block| block }
252
- end
253
-
254
244
  def configure_mock_framework
255
245
  require_mock_framework_adapter
256
246
  RSpec::Core::ExampleGroup.send(:include, RSpec::Core::MockFrameworkAdapter)
@@ -13,26 +13,31 @@ module RSpec
13
13
  def initialize(args)
14
14
  @args = args
15
15
  end
16
-
16
+
17
17
  def configure(config)
18
- sorted_keys.each do |key|
18
+ keys = options.keys
19
+ keys.unshift(:requires) if keys.delete(:requires)
20
+ keys.unshift(:libs) if keys.delete(:libs)
21
+ keys.each do |key|
19
22
  config.send("#{key}=", options[key])
20
23
  end
21
24
  end
22
-
23
- def sorted_keys
24
- options.keys.sort{|a,b| a.to_s <=> b.to_s}
25
- end
26
-
25
+
27
26
  def drb_argv
28
27
  argv = []
29
- argv << "--color" if options[:color_enabled]
28
+ argv << "--color" if options[:color_enabled]
30
29
  argv << "--profile" if options[:profile_examples]
31
30
  argv << "--backtrace" if options[:full_backtrace]
32
31
  argv << "--format" << options[:formatter] if options[:formatter]
33
32
  argv << "--line_number" << options[:line_number] if options[:line_number]
34
33
  argv << "--options_file" << options[:options_file] if options[:options_file]
35
34
  argv << "--example" << options[:full_description].source if options[:full_description]
35
+ (options[:libs] || []).each do |path|
36
+ argv << "-I" << path
37
+ end
38
+ (options[:requires] || []).each do |path|
39
+ argv << "--require" << path
40
+ end
36
41
  argv + options[:files_or_directories_to_run]
37
42
  end
38
43
 
@@ -1,9 +1,8 @@
1
1
  module RSpec
2
2
  module Core
3
3
  class DRbCommandLine
4
- def initialize(argv)
5
- @options = RSpec::Core::ConfigurationOptions.new(argv)
6
- @options.parse_options
4
+ def initialize(options)
5
+ @options = options
7
6
  end
8
7
 
9
8
  def drb_port