rspec-core 2.0.0.rc → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -14,7 +14,9 @@ gem "syntax"
14
14
  gem "rspec-core", :path => "."
15
15
  gem "rspec-expectations", :path => "../rspec-expectations"
16
16
  gem "rspec-mocks", :path => "../rspec-mocks"
17
+ gem "relish"
17
18
  unless RUBY_PLATFORM == "java"
19
+ gem "ruby-prof"
18
20
  case RUBY_VERSION
19
21
  when /^1.9.2/
20
22
  gem "ruby-debug19"
@@ -1,5 +1,16 @@
1
1
  ## rspec-core release history (incomplete)
2
2
 
3
+ ### 2.0.0 / 2010-10-10
4
+
5
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.rc...v2.0.0)
6
+
7
+ * RSpec-1 compatibility
8
+ * Rake task uses ENV["SPEC"] as file list if present
9
+
10
+ * Bug fixes
11
+ * Bug Fix: optparse --out foo.txt (Leonardo Bessa)
12
+ * Suppress color codes for non-tty output (except autotest)
13
+
3
14
  ### 2.0.0.rc / 2010-10-05
4
15
 
5
16
  [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.0.beta.22...v2.0.0.rc)
@@ -8,7 +8,7 @@ See [Upgrade.markdown](http://github.com/rspec/rspec-core/blob/master/Upgrade.ma
8
8
 
9
9
  ## Install
10
10
 
11
- gem install rspec --prerelease
11
+ gem install rspec -v 2.0.0
12
12
 
13
13
  This will install the rspec, rspec-core, rspec-expectations and rspec-mocks
14
14
  gems.
data/Rakefile CHANGED
@@ -10,48 +10,57 @@ require "rspec/core/rake_task"
10
10
  require "rspec/core/version"
11
11
  require "cucumber/rake/task"
12
12
 
13
- RSpec::Core::RakeTask.new(:spec)
14
-
15
- desc "Run all examples using rcov"
16
- RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
17
- t.rcov = true
18
- t.rcov_opts = %[-Ilib -Ispec --exclude "mocks,expectations,gems/*,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*"]
19
- t.rcov_opts << %[--no-html --aggregate coverage.data]
13
+ class Cucumber::Rake::Task::ForkedCucumberRunner
14
+ # When cucumber shells out, we still need it to run in the context of our
15
+ # bundle.
16
+ def run
17
+ sh "bundle exec #{RUBY} " + args.join(" ")
18
+ end
20
19
  end
21
20
 
22
21
  task :cleanup_rcov_files do
23
22
  rm_rf 'coverage.data'
24
23
  end
25
24
 
26
- task :clobber do
27
- rm_rf 'pkg'
28
- rm_rf 'tmp'
29
- rm_rf 'coverage'
25
+ desc "Run all examples"
26
+ RSpec::Core::RakeTask.new(:spec) do |t|
27
+ t.rspec_path = 'bin/rspec'
28
+ t.rspec_opts = %w[--color]
30
29
  end
31
30
 
32
- class Cucumber::Rake::Task::ForkedCucumberRunner
33
- # When cucumber shells out, we still need it to run in the context of our
34
- # bundle.
35
- def run
36
- sh "bundle exec #{RUBY} " + args.join(" ")
31
+ Cucumber::Rake::Task.new(:cucumber)
32
+
33
+ namespace :spec do
34
+ desc "Run all examples using rcov"
35
+ RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
36
+ t.rcov = true
37
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
38
+ t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
37
39
  end
38
40
  end
39
41
 
40
- if RUBY_VERSION.to_f >= 1.9
41
- Cucumber::Rake::Task.new(:cucumber) do |t|
42
+ namespace :cucumber do
43
+ desc "Run cucumber features using rcov"
44
+ Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
42
45
  t.cucumber_opts = %w{--format progress}
43
- end
44
-
45
- task :default => [:spec, :cucumber]
46
- else
47
- Cucumber::Rake::Task.new(:cucumber) do |t|
48
46
  t.rcov = true
49
- t.rcov_opts = %[-Ilib -Ispec --exclude "mocks,expectations,gems/*,features,spec/ruby_forker,spec/rspec,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*"]
47
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
50
48
  t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
51
- t.cucumber_opts = %w{--format progress}
52
49
  end
50
+ end
51
+
52
+ task :default => [:spec, :cucumber]
53
+
54
+ task :clobber do
55
+ rm_rf 'pkg'
56
+ rm_rf 'tmp'
57
+ rm_rf 'coverage'
58
+ end
53
59
 
54
- task :default => [:rcov, :cucumber]
60
+ desc "Push cukes to relishapp using the relish-client-gem"
61
+ task :relish, :version do |t, args|
62
+ raise "rake relish[VERSION]" unless args[:version]
63
+ sh "bundle exec relish --organization rspec --project rspec-core -v #{args[:version]} push"
55
64
  end
56
65
 
57
66
  Rake::RDocTask.new do |rdoc|
@@ -1,6 +1,6 @@
1
1
  # Upgrade to rspec-core-2.0
2
2
 
3
- ## What's changed since rspec-1
3
+ ## What's changed since RSpec-1
4
4
 
5
5
  ### rspec command
6
6
 
@@ -8,6 +8,27 @@ The command to run specs is now `rspec` instead of `spec`.
8
8
 
9
9
  rspec ./spec
10
10
 
11
+ #### Co-habitation of rspec-1 and rspec-2
12
+
13
+ Early beta versions of RSpec-2 included a `spec` command, which conflicted with
14
+ the RSpec-1 `spec` command because RSpec-1's was installed by the rspec gem,
15
+ while RSpec-2's is installed by the rspec-core gem.
16
+
17
+ If you installed one of these early versions, the safest bet is to uninstall
18
+ rspec-1 and rspec-core-2, and then reinstall both. After you do this, you will
19
+ be able to run rspec-2 like this:
20
+
21
+ `rspec ./spec`
22
+
23
+ ... and rspec-1 like this:
24
+
25
+ `spec _1.3.1_ ./spec`
26
+
27
+ Rubygems inspects the first argument to any gem executable to see if it's
28
+ formatted like a version number surrounded by underscores. If so, it uses that
29
+ version (e.g. `1.3.1`). If not, it uses the most recent version (e.g.
30
+ `2.0.0`).
31
+
11
32
  ### rake task
12
33
 
13
34
  The RSpec rake task has moved to:
@@ -43,7 +64,7 @@ Or, if you're using bundler:
43
64
 
44
65
  The `autospec` command is a thing of the past.
45
66
 
46
- ### RSpec
67
+ ### RSpec is the new Spec
47
68
 
48
69
  The root namespace (top level module) is now `RSpec` instead of `Spec`, and
49
70
  the root directory under `lib` within all of the `rspec` gems is `rspec` instead of `spec`.
@@ -66,6 +87,37 @@ options. Precedence is:
66
87
  ./.rspec
67
88
  ~/.rspec
68
89
 
90
+ ### Bones
91
+
92
+ Bones produces a handy little Rakefile to provide several services including
93
+ running specs. The current version (3.4.7) still assumes RSpec-1. To bring its
94
+ Rakefile into conformance with RSpec-2 a few changes are necessary.
95
+
96
+ 1. The require line has changed to `require 'spec/rake/spectask'`
97
+
98
+ 2. The `spec_opts` accessor has been deprecated in favor of `rspec_opts`. Also,
99
+ the `rspec` command no longer supports the `--options` command line option
100
+ so the options must be embedded directly in the Rakefile, or stored in the
101
+ `.rspec` files mentioned above.
102
+
103
+ 3. The `spec_files` accessor has been replaced by `pattern`.
104
+
105
+ Here is a complete example:
106
+
107
+ # rspec-1
108
+ Spec::Rake::SpecTask.new do |t|
109
+ t.spec_opts = ['--options', "\"spec/spec.opts\""]
110
+ t.spec_files = FileList['spec/**/*.rb']
111
+ end
112
+
113
+ becomes:
114
+
115
+ # rspec-2
116
+ RSpec::Core::RakeTask.new do |t|
117
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
118
+ t.pattern = 'spec/**/*_spec.rb'
119
+ end
120
+
69
121
  ### `context` is no longer a top-level method
70
122
 
71
123
  We removed `context` from the main object because it was creating conflicts with
@@ -1,12 +1,19 @@
1
- # Cucumber features
1
+ rspec-core provides the structure for RSpec code examples:
2
2
 
3
- RSpec is specified using both RSpec and
4
- [Cucumber](http://github.com/aslakhellesoy/cucumber). Cucumber provides
5
- _executable documentation_. This means that the _.feature_ files below this
6
- directory serve as specification, documentation _and_ regression tests of the
7
- behaviour.
3
+ describe Account do
4
+ it "has a balance of zero when first opened" do
5
+ # example code goes here - for more on the
6
+ # code inside the examples, see rspec-expectations
7
+ # and rspec-mocks
8
+ end
9
+ end
8
10
 
9
11
  ## Issues
10
12
 
11
- If you find this documentation incomplete or confusing, please [submit an
12
- issue](http://github.com/rspec/rspec-core/issues).
13
+ The documentation for rspec-core is a work in progress. We'll be adding
14
+ Cucumber features over time, and clarifying existing ones. If you have
15
+ specific features you'd like to see added, find the existing documentation
16
+ incomplete or confusing, or, better yet, wish to write a missing Cucumber
17
+ feature yourself, please [submit an
18
+ issue](http://github.com/rspec/rspec-core/issues) or a [pull
19
+ request](http://github.com/rspec/rspec-core).
@@ -1,6 +1,7 @@
1
1
  Feature: configure
2
2
 
3
- Use --configure to generate configuration files.
3
+ Use the --configure option on the command line to generate configuration
4
+ files.
4
5
 
5
6
  The only supported argument, so far, is "autotest", which creates an
6
7
  autotest/discover.rb file in your project root directory.
@@ -18,6 +18,12 @@ Feature: read command line configuration options from files
18
18
  """
19
19
  describe "color_enabled" do
20
20
  context "when set with RSpec.configure" do
21
+ before do
22
+ # color is disabled for non-tty output, so stub the output stream
23
+ # to say it is tty, even though we're running this with cucumber
24
+ RSpec.configuration.output_stream.stub(:tty?) { true }
25
+ end
26
+
21
27
  it "is true" do
22
28
  RSpec.configuration.should be_color_enabled
23
29
  end
@@ -155,6 +155,29 @@ Feature: before and after hooks
155
155
  after all ran
156
156
  """
157
157
 
158
+ Scenario: failure in after(:all) block
159
+ Given a file named "after_all_spec.rb" with:
160
+ """
161
+ describe "an error in after(:all)" do
162
+ after(:all) do
163
+ raise StandardError.new("Boom!")
164
+ end
165
+
166
+ it "passes this example" do
167
+ end
168
+
169
+ it "passes this example, too" do
170
+ end
171
+ end
172
+ """
173
+ When I run "rspec after_all_spec.rb"
174
+ Then the output should contain "2 examples, 0 failures"
175
+ And the output should contain:
176
+ """
177
+ An error occurred in an after(:all) hook.
178
+ StandardError: Boom!
179
+ """
180
+
158
181
  Scenario: define before and after blocks in configuration
159
182
  Given a file named "befores_in_configuration_spec.rb" with:
160
183
  """
@@ -10,7 +10,10 @@ class Autotest::Rspec2 < Autotest
10
10
  super
11
11
  clear_mappings
12
12
  setup_rspec_project_mappings
13
- self.failed_results_re = /^\s*\d\)\s(.*?$\n.*?$).*?#\s(.*?):/m
13
+
14
+ # Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
15
+ # 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
14
17
  self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
15
18
  end
16
19
 
@@ -38,11 +41,15 @@ class Autotest::Rspec2 < Autotest
38
41
 
39
42
  def make_test_cmd(files_to_test)
40
43
  files_to_test.empty? ? '' :
41
- "#{ruby} #{require_rubygems}#{SPEC_PROGRAM} #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
44
+ "#{bundle_exec}#{ruby} #{require_rubygems}-S #{SPEC_PROGRAM} --autotest #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
45
+ end
46
+
47
+ def bundle_exec
48
+ using_bundler? ? "bundle exec " : ""
42
49
  end
43
50
 
44
51
  def require_rubygems
45
- using_bundler? ? "" : defined?(:Gem) ? "-rrubygems " : ""
52
+ using_bundler? ? "" : defined?(:Gem) ? "-rrubygems " : " "
46
53
  end
47
54
 
48
55
  def normalize(files_to_test)
@@ -52,10 +59,6 @@ class Autotest::Rspec2 < Autotest
52
59
  end
53
60
  end
54
61
 
55
- def ruby
56
- using_bundler? ? "bundle exec" : super
57
- end
58
-
59
62
  def using_bundler?
60
63
  File.exists?('./Gemfile')
61
64
  end
@@ -12,44 +12,22 @@ module RSpec
12
12
  end
13
13
 
14
14
  def run(err, out)
15
- @options.configure(@configuration)
16
15
  @configuration.error_stream = err
17
16
  @configuration.output_stream ||= out
17
+ @options.configure(@configuration)
18
18
  @configuration.load_spec_files
19
19
  @configuration.configure_mock_framework
20
20
  @world.announce_inclusion_filter
21
21
  @world.announce_exclusion_filter
22
22
 
23
- @configuration.reporter.report(example_count) do |reporter|
23
+ @configuration.reporter.report(@world.example_count) do |reporter|
24
24
  begin
25
25
  @configuration.run_hook(:before, :suite)
26
- example_groups.run_examples(reporter)
26
+ @world.example_groups.map {|g| g.run(reporter)}.all?
27
27
  ensure
28
28
  @configuration.run_hook(:after, :suite)
29
29
  end
30
30
  end
31
-
32
- example_groups.success?
33
- end
34
-
35
- private
36
-
37
- def example_count
38
- @world.example_count
39
- end
40
-
41
- module ExampleGroups
42
- def run_examples(reporter)
43
- @success = self.inject(true) {|success, group| success &= group.run(reporter)}
44
- end
45
-
46
- def success?
47
- @success ||= false
48
- end
49
- end
50
-
51
- def example_groups
52
- @world.example_groups.extend(ExampleGroups)
53
31
  end
54
32
  end
55
33
  end
@@ -23,7 +23,6 @@ module RSpec
23
23
  add_setting :out, :alias => :output_stream
24
24
  add_setting :drb
25
25
  add_setting :drb_port
26
- add_setting :color_enabled
27
26
  add_setting :profile_examples
28
27
  add_setting :fail_fast, :default => false
29
28
  add_setting :run_all_when_everything_filtered
@@ -34,16 +33,17 @@ module RSpec
34
33
  add_setting :files_to_run
35
34
  add_setting :include_or_extend_modules
36
35
  add_setting :backtrace_clean_patterns
36
+ add_setting :autotest
37
37
 
38
38
  def initialize
39
+ @color_enabled = false
39
40
  self.include_or_extend_modules = []
40
41
  self.files_to_run = []
41
42
  self.backtrace_clean_patterns = [
42
43
  /\/lib\d*\/ruby\//,
43
- /bin\/rcov:/,
44
- /vendor\/rails/,
45
- /bin\/rspec/,
46
- /bin\/spec/,
44
+ /bin\//,
45
+ /gems/,
46
+ /spec\/spec_helper\.rb/,
47
47
  /lib\/rspec\/(core|expectations|matchers|mocks)/
48
48
  ]
49
49
  end
@@ -129,20 +129,27 @@ module RSpec
129
129
  settings[:backtrace_clean_patterns] = []
130
130
  end
131
131
 
132
- remove_method :color_enabled=
132
+ def color_enabled
133
+ @color_enabled && (output_to_tty? || autotest?)
134
+ end
135
+
136
+ def color_enabled?
137
+ !!color_enabled
138
+ end
133
139
 
134
140
  def color_enabled=(bool)
135
141
  return unless bool
136
- settings[:color_enabled] = true
142
+ @color_enabled = true
137
143
  if bool && ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
138
- orig_output_stream = settings[:output_stream]
144
+ using_stdout = settings[:output_stream] == $stdout
145
+ using_stderr = settings[:error_stream] == $stderr
139
146
  begin
140
147
  require 'Win32/Console/ANSI'
148
+ settings[:output_stream] = $stdout if using_stdout
149
+ settings[:error_stream] = $stderr if using_stderr
141
150
  rescue LoadError
142
151
  warn "You must 'gem install win32console' to use colour on Windows"
143
- settings[:color_enabled] = false
144
- ensure
145
- settings[:output_stream] = orig_output_stream
152
+ @color_enabled = false
146
153
  end
147
154
  end
148
155
  end
@@ -301,6 +308,14 @@ EOM
301
308
 
302
309
  private
303
310
 
311
+ def output_to_tty?
312
+ begin
313
+ settings[:output_stream].tty?
314
+ rescue NoMethodError
315
+ false
316
+ end
317
+ end
318
+
304
319
  def built_in_formatter(key)
305
320
  case key.to_s
306
321
  when 'd', 'doc', 'documentation', 's', 'n', 'spec', 'nested'