rspec 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,9 +1,24 @@
1
1
  = RSpec Changelog
2
2
 
3
+ == Version 0.6.1
4
+ This is the "fix the most annoying bugs release" of RSpec. There are 9 bugfixes this time.
5
+ Things that may break backwards compatibility:
6
+ 1) Spec::Rake::SpecTask no longer has the options attribute. Use ruby_opts, spec_opts and rcov_opts instead.
7
+
8
+ * Fixed [#4891] RCOV task failing on windows
9
+ * Fixed [#4896] Shouldn't modify user's $LOAD_PATH (Tip from Gavin Sinclair)
10
+ * Fixed [#5369] ruby -w: warnings in RSpec 0.5.16 (Tip from Suraj Kurapati)
11
+ * Applied [#5141] SpecMatcher doesn't escape strings before matching (Patch from Nikolai Weibull).
12
+ * Fixed [#5224] Move 'require diff-lcs' from test_helper.rb to diff_test.rb (Tip from Chris Roos)
13
+ * Applied [#5449] Rake stats for specs (Patch from Nick Sieger)
14
+ * Applied [#5468, #5058] Fix spec runner to correctly run controller specs (Patch from Daniel Siemssen)
15
+ * Applied fixes to rails_spec_runner to improve its ability to run several times. (Patch from Daniel Siemssen)
16
+ * Changed RCov::VerifyTask to fail if the coverage is above the threshold. This is to ensure it gets bumped when coverage improves.
17
+
3
18
  == Version 0.6.0
4
19
  This release makes an official commitment to underscore_syntax (with no more support for dot.syntax)
5
20
 
6
- * Fixed bug (5292) that caused mock argument matching to fail on classes that overrided ==
21
+ * Fixed bug (5292) that caused mock argument matching to fail
7
22
  * Converted ALL tests to use underscore syntax
8
23
  * Fixed all remaining problems with underscores revealed by converting all the tests to underscores
9
24
  * Enhanced sugar to support combinations of methods (i.e. once.and_return)
@@ -17,6 +32,7 @@ This release improves Rails support and test2spec translation.
17
32
 
18
33
  * Fixed underscore problems that occurred when RSpec was used in Rails
19
34
  * Simplified the Rails support by packaging it as a plugin instead of a generator gem.
35
+ * Fixed [#5063] 'rspec_on_rails' require line in spec_helper.rb
20
36
  * Added pre_commit rake task to reduce risk of regressions. Useful for rspec developers and patchers.
21
37
  * Added failure_message to RSpec Rake task
22
38
  * test2spec now defines converted helper methods outside of the setup block (bug #5057).
data/Rakefile CHANGED
@@ -68,6 +68,14 @@ Spec::Rake::SpecTask.new('test2spec_test' => :test2spec) do |t|
68
68
  t.failure_message = "**** Translated specs failed. See doc/output/tools/rspec_specs.html ****"
69
69
  end
70
70
 
71
+ desc 'Verify that no warnings occur'
72
+ task :verify_warnings do
73
+ `ruby -w #{File.dirname(__FILE__) + '/bin/spec'} --help 2> warnings.txt`
74
+ warnings = File.open('warnings.txt').read
75
+ File.rm 'warnings.txt'
76
+ raise "There were warnings:\n#{warnings}" if warnings =~ /warning/n
77
+ end
78
+
71
79
  desc 'Generate HTML documentation for website'
72
80
  task :webgen => :test2spec do
73
81
  Dir.chdir 'doc' do
@@ -165,11 +173,11 @@ task :tag do
165
173
  end
166
174
 
167
175
  desc "Run this task before you commit. You should see 'OK TO COMMIT'"
168
- task :pre_commit => [:website, :examples, :failing_examples_with_html, :rails_pre_commit, :commit_ok]
176
+ task :pre_commit => [:verify_warnings, :website, :examples, :failing_examples_with_html, :rails_pre_commit, :commit_ok]
169
177
 
170
178
  task :rails_pre_commit do
171
179
  Dir.chdir 'vendor/rspec_on_rails' do
172
- `rake pre_commit`
180
+ `rake pre_commit --verbose`
173
181
  raise "RSpec on Rails pre_commit failed\ncd to vendor/rspec_on_rails and run rake pre_commit for more details" if $? != 0
174
182
  end
175
183
  end
@@ -30,5 +30,4 @@ context "Airport at home" do
30
30
  teardown do
31
31
  @airport = nil
32
32
  end
33
-
34
33
  end
@@ -1,5 +1,3 @@
1
- $LOAD_PATH.push File.dirname(__FILE__) + '/../lib'
2
-
3
1
  require 'spec/version'
4
2
  require 'spec/api'
5
3
  require 'spec/runner'
@@ -100,7 +100,7 @@ module Spec
100
100
  if @args_to_yield.length != block.arity
101
101
  Kernel::raise Spec::Api::MockExpectationError, "Wrong arity of passed block. Expected #{@args_to_yield.size}"
102
102
  end
103
- block.call *@args_to_yield
103
+ block.call(*@args_to_yield)
104
104
  end
105
105
 
106
106
  def invoke_return_block(args, block)
@@ -18,7 +18,8 @@ module Spec
18
18
  object = self
19
19
  calls = sym.to_s.split("_")
20
20
  while calls.length > 1
21
- break if (object.respond_to?calls.join("_"))
21
+ remainder = calls.join("_")
22
+ break if (object.respond_to?(remainder))
22
23
  call = calls.shift
23
24
  object = object.__send__(call)
24
25
  break if call == "be"
@@ -1,6 +1,7 @@
1
1
  module RCov
2
2
  # A task that can verify that the RCov coverage doesn't
3
- # drop below a certain threshold.
3
+ # drop below a certain threshold. It should be run after
4
+ # running Spec::Rake::SpecTask.
4
5
  class VerifyTask < Rake::TaskLib
5
6
  # Name of the task. Defaults to :rcov_verify
6
7
  attr_accessor :name
@@ -14,8 +15,8 @@ module RCov
14
15
  attr_accessor :verbose
15
16
 
16
17
  # The threshold value (in percent) for coverage. If the
17
- # actual coverage is below this value, the task will raise an
18
- # exception
18
+ # actual coverage is not equal to this value, the task will raise an
19
+ # exception.
19
20
  attr_accessor :threshold
20
21
 
21
22
  def initialize(name=:rcov_verify)
@@ -39,6 +40,7 @@ module RCov
39
40
  end
40
41
  puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
41
42
  raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
43
+ raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value." if total_coverage > threshold
42
44
  end
43
45
  end
44
46
  end
@@ -6,142 +6,165 @@ require 'rake'
6
6
  require 'rake/tasklib'
7
7
 
8
8
  module Spec
9
- module Rake
10
-
11
- # A task that runs a set of RSpec contexts.
12
- #
13
- # Example:
14
- #
15
- # Rake::SpecTask.new do |t|
16
- # t.libs << "spec"
17
- # t.spec_files = FileList['spec/**/*_spec.rb']
18
- # end
19
- #
20
- class SpecTask < ::Rake::TaskLib
21
-
22
- # Name of spec task. (default is :spec)
23
- attr_accessor :name
24
-
25
- # List of directories to added to $LOAD_PATH before running the
26
- # specs. (default is 'lib')
27
- attr_accessor :libs
28
-
29
- # Options poassed to spec
30
- attr_accessor :spec_opts
31
-
32
- # Test options passed to the spec suite. An explicit
33
- # SPECOPTS=opts on the command line will override this. (default
34
- # is NONE)
35
- attr_accessor :options
36
-
37
- # Request that the specs be run with the warning flag set.
38
- # E.g. warning=true implies "ruby -w" used to run the specs.
39
- attr_accessor :warning
40
-
41
- # Glob pattern to match spec files. (default is 'spec/spec*.rb')
42
- attr_accessor :pattern
43
-
44
- # Whether or not to use rcov (default is false)
45
- # See http://eigenclass.org/hiki.rb?rcov
46
- attr_accessor :rcov
47
-
48
- # Where output is written. Default is STDOUT.
49
- attr_accessor :out
50
-
51
- # Array of commandline options to pass to ruby (or rcov) when running specs.
52
- attr_accessor :ruby_opts
53
-
54
- # Whether or not to fail Rake when an error occurs (typically when specs fail).
55
- # Default is true
56
- attr_accessor :fail_on_error
57
-
58
- # A message to print to stdout when there are failures. Useful if +out+ is used.
59
- attr_accessor :failure_message
60
-
61
- # Explicitly define the list of spec files to be included in a
62
- # spec. +list+ is expected to be an array of file names (a
63
- # FileList is acceptable). If both +pattern+ and +spec_files+ are
64
- # used, then the list of spec files is the union of the two.
65
- def spec_files=(list)
66
- @spec_files = list
67
- end
9
+ module Rake
10
+
11
+ # A Rake task that runs a set of RSpec contexts.
12
+ #
13
+ # Example:
14
+ #
15
+ # Rake::SpecTask.new do |t|
16
+ # t.warning = true
17
+ # end
18
+ #
19
+ # This will create a task that can be run with:
20
+ #
21
+ # rake spec
22
+ #
23
+ class SpecTask < ::Rake::TaskLib
24
+
25
+ # Name of spec task. (default is :spec)
26
+ attr_accessor :name
27
+
28
+ # Array of directories to be added to $LOAD_PATH before running the
29
+ # specs. Defaults to ['lib']
30
+ attr_accessor :libs
31
+
32
+ # If true, requests that the specs be run with the warning flag set.
33
+ # E.g. warning=true implies "ruby -w" used to run the specs. Defaults to false.
34
+ attr_accessor :warning
35
+
36
+ # Glob pattern to match spec files. (default is 'spec/spec*.rb')
37
+ attr_accessor :pattern
38
+
39
+ # Array of commandline options to pass to RSpec. Defaults to [].
40
+ attr_accessor :spec_opts
41
+
42
+ # Where RSpec's output is written. Defaults to STDOUT.
43
+ attr_accessor :out
44
+
45
+ # Whether or not to use RCov (default is false)
46
+ # See http://eigenclass.org/hiki.rb?rcov
47
+ attr_accessor :rcov
48
+
49
+ # Array of commandline options to pass to RCov. Defaults to ['--exclude', 'lib\/spec,bin\/spec'].
50
+ # Ignored if rcov=false
51
+ attr_accessor :rcov_opts
52
+
53
+ # Directory where the RCov report is written. Defaults to "coverage"
54
+ # Ignored if rcov=false
55
+ attr_accessor :rcov_dir
56
+
57
+ # Array of commandline options to pass to ruby. Defaults to [].
58
+ attr_accessor :ruby_opts
59
+
60
+ # Whether or not to fail Rake when an error occurs (typically when specs fail).
61
+ # Defaults to true.
62
+ attr_accessor :fail_on_error
63
+
64
+ # A message to print to stdout when there are failures.
65
+ attr_accessor :failure_message
66
+
67
+ # Explicitly define the list of spec files to be included in a
68
+ # spec. +list+ is expected to be an array of file names (a
69
+ # FileList is acceptable). If both +pattern+ and +spec_files+ are
70
+ # used, then the list of spec files is the union of the two.
71
+ def spec_files=(list)
72
+ @spec_files = list
73
+ end
68
74
 
69
- # Create a specing task.
70
- def initialize(name=:spec)
71
- @name = name
72
- @libs = ["lib"]
73
- @pattern = nil
74
- @options = nil
75
- @spec_files = nil
76
- @spec_opts = []
77
- @warning = false
78
- @rcov = false
79
- @ruby_opts = []
80
- @out = nil
81
- @fail_on_error = true
82
- yield self if block_given?
83
- @pattern = 'spec/**/*_spec.rb' if @pattern.nil? && @spec_files.nil?
84
- define
85
- end
75
+ # Create a specing task.
76
+ def initialize(name=:spec)
77
+ @name = name
78
+ @libs = ["lib"]
79
+ @pattern = nil
80
+ @spec_files = nil
81
+ @spec_opts = []
82
+ @warning = false
83
+ @ruby_opts = []
84
+ @out = nil
85
+ @fail_on_error = true
86
+ @rcov = false
87
+ @rcov_opts = ['--exclude', 'lib\/spec,bin\/spec']
88
+ @rcov_dir = "coverage"
89
+
90
+ yield self if block_given?
91
+ @pattern = 'spec/**/*_spec.rb' if @pattern.nil? && @spec_files.nil?
92
+ define
93
+ end
94
+
95
+ def define
96
+ #raise "No spec files found." if file_list.empty?
97
+ spec_script = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')
86
98
 
87
- # Create the tasks defined by this task lib.
88
- def define
89
- lib_path = @libs.join(File::PATH_SEPARATOR)
90
- desc "Run specs" + (@name==:spec ? "" : " for #{@name}")
91
- task @name do
92
- specs = file_list
93
- raise "No spec files found." if specs.empty?
94
-
95
- spec = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')
96
- file_prefix = @rcov ? " -- " : ""
97
- interpreter = @rcov ? "rcov" : "ruby"
98
- redirect = @out.nil? ? "" : " > #{@out}"
99
-
100
- @ruby_opts.unshift( "-I#{lib_path}" )
101
- @ruby_opts.unshift( "-w" ) if @warning
102
- @ruby_opts.unshift( '--exclude "lib\/spec\/.*"' ) if @rcov
103
- begin
104
- run interpreter, @ruby_opts.join(" ") +
105
- " \"#{spec}\" " +
106
- " #{@spec_opts.join(' ')} " +
107
- file_prefix +
108
- specs.collect { |fn| "\"#{fn}\"" }.join(' ') +
109
- redirect
110
-
111
- puts @failure_message if @failure_message && ($? != 0)
112
- rescue => e
113
- puts @failure_message if @failure_message
114
- raise e if @fail_on_error
99
+ lib_path = @libs.join(File::PATH_SEPARATOR)
100
+ actual_name = Hash === name ? name.keys.first : name
101
+ unless ::Rake.application.last_comment
102
+ desc "Run RSpec for #{actual_name}" + (@rcov ? " using RCov" : "")
115
103
  end
104
+ task @name do
105
+ RakeFileUtils.verbose(@verbose) do
106
+ ruby_opts = @ruby_opts.clone
107
+ ruby_opts.push( "-I#{lib_path}" )
108
+ ruby_opts.push( "-S rcov" ) if @rcov
109
+ ruby_opts.push( "-w" ) if @warning
110
+
111
+ redirect = @out.nil? ? "" : " > #{@out}"
112
+ # ruby [ruby_opts] -Ilib -S rcov [rcov_opts] bin/spec -- [spec_opts] examples
113
+ # or
114
+ # ruby [ruby_opts] -Ilib bin/spec [spec_opts] examples
115
+ begin
116
+ ruby(
117
+ ruby_opts.join(" ") + " " +
118
+ rcov_option_list +
119
+ (@rcov ? %[ -o "#{@rcov_dir}" ] : "") +
120
+ spec_script + " " +
121
+ (@rcov ? "-- " : "") +
122
+ spec_option_list + " " +
123
+ file_list.collect { |fn| %["#{fn}"] }.join(' ') + " " +
124
+ redirect
125
+ )
126
+ rescue => e
127
+ puts @failure_message if @failure_message
128
+ raise e if @fail_on_error
129
+ end
130
+ end
131
+ end
132
+
133
+ if @rcov
134
+ desc "Remove rcov products for #{actual_name}"
135
+ task paste("clobber_", actual_name) do
136
+ rm_r @rcov_dir rescue nil
137
+ end
138
+
139
+ clobber_task = paste("clobber_", actual_name)
140
+ task :clobber => [clobber_task]
141
+
142
+ task actual_name => clobber_task
143
+ end
144
+ self
116
145
  end
117
- self
118
- end
119
146
 
120
- def file_list # :nodoc:
121
- if ENV['SPEC']
122
- FileList[ ENV['SPEC'] ]
123
- else
124
- result = []
125
- result += @spec_files.to_a if @spec_files
126
- result += FileList[ @pattern ].to_a if @pattern
127
- FileList[result]
147
+ def rcov_option_list # :nodoc:
148
+ return "" unless @rcov
149
+ ENV['RCOVOPTS'] || @rcov_opts.join(" ") || ""
128
150
  end
129
- end
130
151
 
131
- def run(interpreter, *args, &block)
132
- if Hash === args.last
133
- options = args.pop
134
- else
135
- options = {}
152
+ def spec_option_list # :nodoc:
153
+ ENV['RSPECOPTS'] || @spec_opts.join(" ") || ""
136
154
  end
137
- if args.length > 1 then
138
- sh(*([interpreter] + args + [options]), &block)
139
- else
140
- sh("#{interpreter} #{args}", options, &block)
155
+
156
+ def file_list # :nodoc:
157
+ if ENV['SPEC']
158
+ FileList[ ENV['SPEC'] ]
159
+ else
160
+ result = []
161
+ result += @spec_files.to_a if @spec_files
162
+ result += FileList[ @pattern ].to_a if @pattern
163
+ FileList[result]
164
+ end
141
165
  end
142
- end
143
166
 
167
+ end
144
168
  end
145
169
  end
146
- end
147
170
 
@@ -9,7 +9,7 @@ module Spec
9
9
  @context_eval_module.extend ContextEval::ModuleMethods
10
10
  @context_eval_module.include ContextEval::InstanceMethods
11
11
  before_context_eval
12
- @context_eval_module.class_eval &context_block
12
+ @context_eval_module.class_eval(&context_block)
13
13
  end
14
14
 
15
15
  def before_context_eval
@@ -24,15 +24,15 @@ module Spec
24
24
  end
25
25
 
26
26
  def setup(&block)
27
- @context_eval_module.setup &block
27
+ @context_eval_module.setup(&block)
28
28
  end
29
29
 
30
30
  def teardown(&block)
31
- @context_eval_module.teardown &block
31
+ @context_eval_module.teardown(&block)
32
32
  end
33
33
 
34
34
  def specify(spec_name, &block)
35
- @context_eval_module.specify spec_name, &block
35
+ @context_eval_module.specify(spec_name, &block)
36
36
  end
37
37
 
38
38
  def run(reporter, dry_run=false)
@@ -5,17 +5,10 @@ class SpecMatcher
5
5
  @name_to_match = context_and_or_spec_name
6
6
  end
7
7
 
8
- def matches? spec
9
- if matches_context?
10
- if matches_spec?(spec) or context_only?
11
- return true
12
- end
13
- end
14
- if matches_spec? spec
15
- if spec_only? spec
16
- return true
17
- end
18
- end
8
+ def matches?(spec_name)
9
+ return true if matches_context? && (matches_spec?(spec_name) || context_only?)
10
+ return true if matches_spec?(spec_name) && spec_only?(spec_name)
11
+ return false
19
12
  end
20
13
 
21
14
  private
@@ -29,11 +22,11 @@ class SpecMatcher
29
22
  end
30
23
 
31
24
  def matches_context?
32
- @name_to_match =~ /^#{@context_name}\b/
25
+ @name_to_match =~ /^#{Regexp.escape(@context_name)}\b/
33
26
  end
34
27
 
35
- def matches_spec? spec
36
- @name_to_match =~ /\b#{spec}$/
28
+ def matches_spec?(spec_name)
29
+ @name_to_match =~ /\b#{Regexp.escape(spec_name)}$/
37
30
  end
38
31
 
39
32
  end
@@ -3,7 +3,7 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 6
6
- TINY = 0
6
+ TINY = 1
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
@@ -49,7 +49,7 @@ module Spec
49
49
  # should_be_funny(args)
50
50
 
51
51
  def test_should_be_funny_with_args_passes_args_properly
52
- mock = HandCodedMock.new(true)
52
+ mock = HandCodedMock.new(true)
53
53
  assert_nothing_raised do
54
54
  mock.should_be_hungry(1, 2, 3)
55
55
  end
@@ -99,7 +99,7 @@ module Spec
99
99
  # should_be_funny(args)
100
100
 
101
101
  def test_should_not_be_funny_with_args_passes_args_properly
102
- mock = HandCodedMock.new(false)
102
+ mock = HandCodedMock.new(false)
103
103
  assert_nothing_raised do
104
104
  mock.should_not_be_hungry(1, 2, 3)
105
105
  end
@@ -44,6 +44,18 @@ module Spec
44
44
  end
45
45
  end
46
46
 
47
+ def FIXME_test_should_has_key_shouldnt_raise_when_hash_inclusion_is_present
48
+ assert_nothing_raised do
49
+ {"a"=>1}.should_has_key "a"
50
+ end
51
+ end
52
+
53
+ def FIXME_test_should_have_key_shouldnt_raise_when_hash_inclusion_is_present
54
+ assert_nothing_raised do
55
+ {"a"=>1}.should_have_key "a"
56
+ end
57
+ end
58
+
47
59
  def test_should_include_should_raise_when_hash_inclusion_is_missing
48
60
  assert_raise(ExpectationNotMetError) do
49
61
  {"a"=>1}.should_include "b"
@@ -7,6 +7,11 @@ module Spec
7
7
  matcher = SpecMatcher.new("a context with a spec", "a context")
8
8
  assert matcher.matches?("with a spec")
9
9
  end
10
+
11
+ def test_should_match_with_regexp_reserved_characters
12
+ matcher = SpecMatcher.new("a context with #[] a spec", "a context")
13
+ assert matcher.matches?("with #[] a spec")
14
+ end
10
15
 
11
16
  def test_should_not_match_wrong_context
12
17
  matcher = SpecMatcher.new("another context with a spec", "a context")
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.0
7
- date: 2006-08-09 00:00:00 -05:00
8
- summary: RSpec-0.6.0 - BDD for Ruby http://rspec.rubyforge.org/
6
+ version: 0.6.1
7
+ date: 2006-08-23 00:00:00 +02:00
8
+ summary: RSpec-0.6.1 - BDD for Ruby http://rspec.rubyforge.org/
9
9
  require_paths:
10
10
  - lib
11
11
  email: rspec-devel@rubyforge.org
@@ -25,7 +25,6 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
- post_install_message:
29
28
  authors:
30
29
  - Steven Baker, Aslak Hellesoy, Dave Astels, David Chelimsky
31
30
  files: