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

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 (48) hide show
  1. data/.rspec +1 -1
  2. data/Gemfile +7 -6
  3. data/History.md +30 -0
  4. data/Rakefile +3 -43
  5. data/bin/rspec +2 -1
  6. data/features/configuration/{options_file.feature → read_options_from_file.feature} +29 -25
  7. data/features/example_groups/shared_example_group.feature +10 -6
  8. data/features/hooks/before_and_after_hooks.feature +38 -0
  9. data/lib/autotest/rspec2.rb +10 -2
  10. data/lib/rspec/core.rb +8 -0
  11. data/lib/rspec/core/configuration.rb +16 -10
  12. data/lib/rspec/core/configuration_options.rb +7 -3
  13. data/lib/rspec/core/example.rb +7 -0
  14. data/lib/rspec/core/example_group.rb +15 -2
  15. data/lib/rspec/core/extensions/module_eval_with_args.rb +9 -29
  16. data/lib/rspec/core/extensions/object.rb +0 -2
  17. data/lib/rspec/core/formatters/base_formatter.rb +8 -6
  18. data/lib/rspec/core/formatters/base_text_formatter.rb +18 -10
  19. data/lib/rspec/core/formatters/documentation_formatter.rb +9 -9
  20. data/lib/rspec/core/option_parser.rb +0 -4
  21. data/lib/rspec/core/rake_task.rb +85 -39
  22. data/lib/rspec/core/reporter.rb +18 -5
  23. data/lib/rspec/core/runner.rb +8 -18
  24. data/lib/rspec/core/shared_example_group.rb +2 -1
  25. data/lib/rspec/core/version.rb +1 -1
  26. data/rspec-core.gemspec +33 -233
  27. data/spec/autotest/failed_results_re_spec.rb +1 -2
  28. data/spec/autotest/rspec_spec.rb +62 -42
  29. data/spec/rspec/core/configuration_options_spec.rb +12 -29
  30. data/spec/rspec/core/configuration_spec.rb +8 -8
  31. data/spec/rspec/core/example_group_spec.rb +38 -7
  32. data/spec/rspec/core/example_spec.rb +16 -1
  33. data/spec/rspec/core/formatters/base_formatter_spec.rb +6 -0
  34. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +125 -10
  35. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +36 -0
  36. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +282 -0
  37. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +22 -2
  38. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +280 -0
  39. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +280 -0
  40. data/spec/rspec/core/rake_task_spec.rb +128 -0
  41. data/spec/rspec/core/reporter_spec.rb +36 -0
  42. data/spec/rspec/core/runner_spec.rb +0 -18
  43. data/spec/rspec/core/shared_example_group_spec.rb +22 -2
  44. data/spec/rspec/core/world_spec.rb +13 -15
  45. data/spec/spec_helper.rb +2 -1
  46. metadata +110 -13
  47. data/VERSION +0 -1
  48. data/lib/rspec/autorun.rb +0 -2
data/.rspec CHANGED
@@ -1 +1 @@
1
- -Ispec
1
+ --color
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "rake"
4
- gem "jeweler"
5
4
  gem "cucumber"
6
5
  gem "aruba", ">= 0.2.0"
7
6
  gem "autotest"
@@ -15,9 +14,11 @@ gem "syntax"
15
14
  gem "rspec-core", :path => "."
16
15
  gem "rspec-expectations", :path => "../rspec-expectations"
17
16
  gem "rspec-mocks", :path => "../rspec-mocks"
18
- case RUBY_VERSION
19
- when /^1.9.1/
20
- gem "ruby-debug19"
21
- when /^1.8/
22
- gem "ruby-debug"
17
+ unless RUBY_PLATFORM == "java"
18
+ case RUBY_VERSION
19
+ when /^1.9.2/
20
+ gem "ruby-debug19"
21
+ when /^1.8/
22
+ gem "ruby-debug"
23
+ end
23
24
  end
@@ -0,0 +1,30 @@
1
+ ## rspec-core release history (incomplete)
2
+
3
+ ### 2.0.0.beta.22 / 2010-09-12
4
+
5
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.beta.20...v2.0.0.beta.22)
6
+
7
+ * Enhancements
8
+ * removed at_exit hook
9
+ * CTRL-C stops the run (almost) immediately
10
+ * first it cleans things up by running the appropriate after(:all) and after(:suite) hooks
11
+ * then it reports on any examples that have already run
12
+ * cleaned up rake task
13
+ * generate correct task under variety of conditions
14
+ * options are more consistent
15
+ * deprecated redundant options
16
+ * run 'bundle exec autotest' when Gemfile is present
17
+ * support ERB in .rspec options files (Justin Ko)
18
+ * depend on bundler for development tasks (Myron Marsten)
19
+ * add example_group_finished to formatters and reporter (Roman Chernyatchik)
20
+
21
+ * Bug fixes
22
+ * support paths with spaces when using autotest (Andreas Neuhaus)
23
+ * fix module_exec with ruby 1.8.6 (Myron Marsten)
24
+ * remove context method from top-level
25
+ * was conflicting with irb, for example
26
+ * errors in before(:all) are now reported correctly (Chad Humphries)
27
+
28
+ * Removals
29
+ * removed -o --options-file command line option
30
+ * use ./.rspec and ~/.rspec
data/Rakefile CHANGED
@@ -1,54 +1,14 @@
1
1
  require "bundler"
2
2
  Bundler.setup
3
+ Bundler::GemHelper.install_tasks
3
4
 
4
- gem "jeweler", ">= 1.4.0"
5
5
  require "rake"
6
6
  require "yaml"
7
7
 
8
- $:.unshift File.expand_path("../lib", __FILE__)
9
-
10
8
  require "rake/rdoctask"
11
9
  require "rspec/core/rake_task"
12
- require "rspec/core/version"
13
10
  require "cucumber/rake/task"
14
11
 
15
- begin
16
- require "jeweler"
17
- Jeweler::Tasks.new do |gem|
18
- gem.name = "rspec-core"
19
- gem.version = RSpec::Core::Version::STRING
20
- gem.summary = "rspec-core-#{RSpec::Core::Version::STRING}"
21
- gem.description = "RSpec runner and example groups"
22
- gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
23
- gem.homepage = "http://github.com/rspec/rspec-core"
24
- gem.authors = ["Chad Humphries", "David Chelimsky"]
25
- gem.rubyforge_project = "rspec"
26
- gem.add_development_dependency "rspec-expectations", ">= #{RSpec::Core::Version::STRING}"
27
- gem.add_development_dependency "rspec-mocks", ">= #{RSpec::Core::Version::STRING}"
28
- gem.add_development_dependency "cucumber", ">= 0.5.3"
29
- gem.add_development_dependency "autotest", ">= 4.2.9"
30
- gem.post_install_message = <<-EOM
31
- #{"*"*50}
32
-
33
- Thank you for installing #{gem.summary}
34
-
35
- Please be sure to look at Upgrade.markdown to see what might have changed
36
- since the last release.
37
-
38
- #{"*"*50}
39
- EOM
40
- end
41
- rescue LoadError
42
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
43
- end
44
-
45
- namespace :gem do
46
- desc "push to gemcutter"
47
- task :push => :build do
48
- system "gem push pkg/rspec-core-#{RSpec::Core::Version::STRING}.gem"
49
- end
50
- end
51
-
52
12
  RSpec::Core::RakeTask.new(:spec)
53
13
 
54
14
  desc "Run all examples using rcov"
@@ -81,7 +41,7 @@ if RUBY_VERSION.to_f >= 1.9
81
41
  t.cucumber_opts = %w{--format progress}
82
42
  end
83
43
 
84
- task :default => [:check_dependencies, :spec, :cucumber]
44
+ task :default => [:spec, :cucumber]
85
45
  else
86
46
  Cucumber::Rake::Task.new(:cucumber) do |t|
87
47
  t.rcov = true
@@ -90,7 +50,7 @@ else
90
50
  t.cucumber_opts = %w{--format progress}
91
51
  end
92
52
 
93
- task :default => [:check_dependencies, :rcov, :cucumber]
53
+ task :default => [:rcov, :cucumber]
94
54
  end
95
55
 
96
56
  Rake::RDocTask.new do |rdoc|
data/bin/rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rspec/autorun'
2
+ require 'rspec/core'
3
+ exit RSpec::Core::Runner.run(ARGV, $stderr, $stdout)
@@ -1,27 +1,16 @@
1
- Feature: spec/spec.opts
1
+ Feature: read command line configuration options from files
2
2
 
3
- For backwards compatibility with rspec-1, you can write command
4
- line options in a spec/spec.opts file and it will be loaded
5
- automatically.
3
+ RSpec will read command line configuration options from files in
4
+ two different locations:
5
+
6
+ Local: "./.rspec" (i.e. in the project's root directory)
7
+ Global: "~/.rspec" (i.e. in the user's home directory)
6
8
 
7
- Options declared in spec/spec.opts will override configuration
8
- set up in RSpec.configure blocks.
9
-
10
- Scenario: color set in RSpec.configure
11
- Given a file named "spec/example_spec.rb" with:
12
- """
13
- RSpec.configure {|c| c.color_enabled = true }
14
-
15
- describe "color_enabled" do
16
- context "when set with RSpec.configure" do
17
- it "is true" do
18
- RSpec.configuration.color_enabled?.should be_true
19
- end
20
- end
21
- end
22
- """
23
- When I run "rspec ./spec/example_spec.rb"
24
- Then the output should contain "1 example, 0 failures"
9
+ Options declared in the local file override those in the global file, while
10
+ those declared in RSpec.configure will override any ".rspec" file.
11
+
12
+ NOTE: For backwards compatibility with rspec-1, you can write command line
13
+ options in a "spec/spec.opts" file and it will be loaded automatically.
25
14
 
26
15
  Scenario: color set in .rspec
27
16
  Given a file named ".rspec" with:
@@ -33,7 +22,7 @@ Feature: spec/spec.opts
33
22
  describe "color_enabled" do
34
23
  context "when set with RSpec.configure" do
35
24
  it "is true" do
36
- RSpec.configuration.color_enabled?.should be_true
25
+ RSpec.configuration.should be_color_enabled
37
26
  end
38
27
  end
39
28
  end
@@ -41,7 +30,7 @@ Feature: spec/spec.opts
41
30
  When I run "rspec ./spec/example_spec.rb"
42
31
  Then the output should contain "1 example, 0 failures"
43
32
 
44
- Scenario: formatter set in both (RSpec.configure wins)
33
+ Scenario: formatter set in RSpec.configure overrides .rspec
45
34
  Given a file named ".rspec" with:
46
35
  """
47
36
  --format progress
@@ -64,4 +53,19 @@ Feature: spec/spec.opts
64
53
  """
65
54
  When I run "rspec ./spec/example_spec.rb"
66
55
  Then the output should contain "1 example, 0 failures"
67
-
56
+
57
+ Scenario: using ERB in .rspec
58
+ Given a file named ".rspec" with:
59
+ """
60
+ --format <%= true ? 'documentation' : 'progress' %>
61
+ """
62
+ And a file named "spec/example_spec.rb" with:
63
+ """
64
+ describe "formatter" do
65
+ it "is set to documentation" do
66
+ RSpec.configuration.formatter.should be_an(RSpec::Core::Formatters::DocumentationFormatter)
67
+ end
68
+ end
69
+ """
70
+ When I run "rspec ./spec/example_spec.rb"
71
+ Then the output should contain "1 example, 0 failures"
@@ -104,32 +104,36 @@ Feature: Shared example group
104
104
  Scenario: Passing parameters to a shared example group
105
105
  Given a file named "shared_example_group_params_spec.rb" with:
106
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
107
+ shared_examples_for "a measurable object" do |measurement, measurement_methods|
108
+ measurement_methods.each do |measurement_method|
109
+ it "should return #{measurement} from ##{measurement_method}" do
110
+ subject.send(measurement_method).should == measurement
111
+ end
110
112
  end
111
113
  end
112
114
 
113
115
  describe Array, "with 3 items" do
114
116
  subject { [1, 2, 3] }
115
- it_should_behave_like "a measurable object", :size, 3
117
+ it_should_behave_like "a measurable object", 3, [:size, :length]
116
118
  end
117
119
 
118
120
  describe String, "of 6 characters" do
119
121
  subject { "FooBar" }
120
- it_should_behave_like "a measurable object", :length, 6
122
+ it_should_behave_like "a measurable object", 6, [:size, :length]
121
123
  end
122
124
  """
123
125
  When I run "rspec shared_example_group_params_spec.rb --format documentation"
124
- Then the output should contain "2 examples, 0 failures"
126
+ Then the output should contain "4 examples, 0 failures"
125
127
  And the output should contain:
126
128
  """
127
129
  Array with 3 items
128
130
  it should behave like a measurable object
129
131
  should return 3 from #size
132
+ should return 3 from #length
130
133
 
131
134
  String of 6 characters
132
135
  it should behave like a measurable object
136
+ should return 6 from #size
133
137
  should return 6 from #length
134
138
  """
135
139
 
@@ -97,6 +97,44 @@ Feature: before and after hooks
97
97
  When I run "rspec ./before_all_spec.rb:15"
98
98
  Then the output should contain "1 example, 0 failures"
99
99
 
100
+ Scenario: failure in before(:all) block
101
+ Given a file named "before_all_spec.rb" with:
102
+ """
103
+ describe "an error in before(:all)" do
104
+ before(:all) do
105
+ raise "oops"
106
+ end
107
+
108
+ it "fails this example" do
109
+ end
110
+
111
+ it "fails this example, too" do
112
+ end
113
+
114
+ after(:all) do
115
+ puts "after all ran"
116
+ end
117
+ end
118
+ """
119
+ When I run "rspec ./before_all_spec.rb --format documentation"
120
+ Then the output should contain "2 examples, 2 failures"
121
+ And the output should contain:
122
+ """
123
+ an error in before(:all)
124
+ fails this example (FAILED - 1)
125
+ fails this example, too (FAILED - 2)
126
+ after all ran
127
+ """
128
+
129
+ When I run "rspec ./before_all_spec.rb:9 --format documentation"
130
+ Then the output should contain "1 example, 1 failure"
131
+ And the output should contain:
132
+ """
133
+ an error in before(:all)
134
+ fails this example, too (FAILED - 1)
135
+ after all ran
136
+ """
137
+
100
138
  Scenario: define before and after blocks in configuration
101
139
  Given a file named "befores_in_configuration_spec.rb" with:
102
140
  """
@@ -38,11 +38,11 @@ class Autotest::Rspec2 < Autotest
38
38
 
39
39
  def make_test_cmd(files_to_test)
40
40
  files_to_test.empty? ? '' :
41
- "#{ruby} #{require_rubygems}#{SPEC_PROGRAM} #{normalize(files_to_test).keys.flatten.join(' ')}"
41
+ "#{ruby} #{require_rubygems}#{SPEC_PROGRAM} #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
42
42
  end
43
43
 
44
44
  def require_rubygems
45
- defined?(:Gem) ? "-rrubygems " : ""
45
+ using_bundler? ? "" : defined?(:Gem) ? "-rrubygems " : ""
46
46
  end
47
47
 
48
48
  def normalize(files_to_test)
@@ -52,4 +52,12 @@ class Autotest::Rspec2 < Autotest
52
52
  end
53
53
  end
54
54
 
55
+ def ruby
56
+ using_bundler? ? "bundle exec" : super
57
+ end
58
+
59
+ def using_bundler?
60
+ File.exists?('./Gemfile')
61
+ end
62
+
55
63
  end
@@ -49,6 +49,10 @@ module RSpec
49
49
 
50
50
  end
51
51
 
52
+ class << self
53
+ attr_accessor :wants_to_quit
54
+ end
55
+
52
56
  def self.world
53
57
  @world ||= RSpec::Core::World.new
54
58
  end
@@ -60,6 +64,10 @@ module RSpec
60
64
  def self.configure
61
65
  yield configuration if block_given?
62
66
  end
67
+
68
+ def self.clear_remaining_example_groups
69
+ world.example_groups.clear
70
+ end
63
71
  end
64
72
 
65
73
  require 'rspec/core/backward_compatibility'
@@ -29,17 +29,23 @@ module RSpec
29
29
  add_setting :filter
30
30
  add_setting :exclusion_filter
31
31
  add_setting :filename_pattern, :default => '**/*_spec.rb'
32
- add_setting :files_to_run, :default => []
33
- add_setting :include_or_extend_modules, :default => []
32
+ add_setting :files_to_run
33
+ add_setting :include_or_extend_modules
34
34
  add_setting :formatter_class, :default => RSpec::Core::Formatters::ProgressFormatter
35
- add_setting :backtrace_clean_patterns, :default => [
36
- /\/lib\/ruby\//,
37
- /bin\/rcov:/,
38
- /vendor\/rails/,
39
- /bin\/rspec/,
40
- /bin\/spec/,
41
- /lib\/rspec\/(core|expectations|matchers|mocks)/
42
- ]
35
+ add_setting :backtrace_clean_patterns
36
+
37
+ def initialize
38
+ self.include_or_extend_modules = []
39
+ self.files_to_run = []
40
+ self.backtrace_clean_patterns = [
41
+ /\/lib\d*\/ruby\//,
42
+ /bin\/rcov:/,
43
+ /vendor\/rails/,
44
+ /bin\/rspec/,
45
+ /bin\/spec/,
46
+ /lib\/rspec\/(core|expectations|matchers|mocks)/
47
+ ]
48
+ end
43
49
 
44
50
  # :call-seq:
45
51
  # add_setting(:name)
@@ -30,7 +30,6 @@ module RSpec
30
30
  argv << "--backtrace" if options[:full_backtrace]
31
31
  argv << "--format" << options[:formatter] if options[:formatter]
32
32
  argv << "--line_number" << options[:line_number] if options[:line_number]
33
- argv << "--options_file" << options[:options_file] if options[:options_file]
34
33
  argv << "--example" << options[:full_description].source if options[:full_description]
35
34
  (options[:libs] || []).each do |path|
36
35
  argv << "-I" << path
@@ -77,10 +76,15 @@ module RSpec
77
76
  def parse_options_file(path)
78
77
  Parser.parse(args_from_options_file(path))
79
78
  end
80
-
79
+
81
80
  def args_from_options_file(path)
82
81
  return [] unless File.exist?(path)
83
- File.readlines(path).map {|l| l.split}.flatten
82
+ config_string = options_file_as_erb_string(path)
83
+ config_string.split(/\n+/).map {|l| l.split}.flatten
84
+ end
85
+
86
+ def options_file_as_erb_string(path)
87
+ ERB.new(IO.read(path)).result(binding)
84
88
  end
85
89
 
86
90
  def local_options_file(options)
@@ -37,6 +37,7 @@ module RSpec
37
37
  end
38
38
 
39
39
  def run(example_group_instance, reporter)
40
+ return if RSpec.wants_to_quit
40
41
  @example_group_instance = example_group_instance
41
42
  @example_group_instance.example = self
42
43
 
@@ -73,6 +74,12 @@ module RSpec
73
74
  @exception ||= exception
74
75
  end
75
76
 
77
+ def fail_fast(reporter, exception)
78
+ start(reporter)
79
+ set_exception(exception)
80
+ finish(reporter)
81
+ end
82
+
76
83
  private
77
84
 
78
85
  def with_pending_capture(&block)
@@ -20,7 +20,6 @@ module RSpec
20
20
  end
21
21
 
22
22
  def self.inherited(klass)
23
- RSpec::Core::Runner.autorun
24
23
  world.example_groups << klass if klass.superclass == ExampleGroup
25
24
  end
26
25
 
@@ -67,10 +66,12 @@ module RSpec
67
66
  shared_block = world.shared_example_groups[name]
68
67
  raise "Could not find shared example group named \#{name.inspect}" unless shared_block
69
68
 
70
- describe("#{report_label || "it should behave like"} \#{name}") do
69
+ group = describe("#{report_label || "it should behave like"} \#{name}") do
71
70
  module_eval_with_args *args, &shared_block
72
71
  module_eval &customization_block if customization_block
73
72
  end
73
+ group.metadata[:shared_group_name] = name
74
+ group
74
75
  end
75
76
  END_RUBY
76
77
  end
@@ -202,19 +203,31 @@ module RSpec
202
203
  end
203
204
 
204
205
  def self.run(reporter)
206
+ if RSpec.wants_to_quit
207
+ RSpec.clear_remaining_example_groups if top_level?
208
+ return
209
+ end
205
210
  @reporter = reporter
206
211
  example_group_instance = new
207
212
  reporter.example_group_started(self)
213
+
208
214
  begin
209
215
  eval_before_alls(example_group_instance)
210
216
  result_for_this_group = run_examples(example_group_instance, reporter)
211
217
  results_for_descendants = children.map {|child| child.run(reporter)}.all?
212
218
  result_for_this_group && results_for_descendants
219
+ rescue Exception => ex
220
+ fail_filtered_examples(ex, reporter)
213
221
  ensure
214
222
  eval_after_alls(example_group_instance)
223
+ reporter.example_group_finished(self)
215
224
  end
216
225
  end
217
226
 
227
+ def self.fail_filtered_examples(exception, reporter)
228
+ filtered_examples.each { |example| example.fail_fast(reporter, exception) }
229
+ end
230
+
218
231
  def self.run_examples(instance, reporter)
219
232
  filtered_examples.map do |example|
220
233
  begin