rspec 0.5.15 → 0.5.16

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.
data/CHANGES CHANGED
@@ -1,5 +1,14 @@
1
1
  = RSpec Changelog
2
2
 
3
+ == Version 0.5.16
4
+ This release improves Rails support and test2spec translation.
5
+
6
+ * Fixed underscore problems that occurred when RSpec was used in Rails
7
+ * Simplified the Rails support by packaging it as a plugin instead of a generator gem.
8
+ * Added pre_commit rake task to reduce risk of regressions. Useful for rspec developers and patchers.
9
+ * Added failure_message to RSpec Rake task
10
+ * test2spec now defines converted helper methods outside of the setup block (bug #5057).
11
+
3
12
  == Version 0.5.15
4
13
  This release removes a prematurely added feature that shouldn't have been added.
5
14
 
data/Rakefile CHANGED
@@ -54,6 +54,7 @@ task :test2spec => :create_test2spec_dir do
54
54
  # Remove the spec translations that we don't care about.
55
55
  rm 'spec/translated/spec/test_to_spec/sexp_transformer_assertion_spec.rb'
56
56
  rm 'spec/translated/spec/test_to_spec/sexp_transformer_spec.rb'
57
+ rm 'spec/translated/r2_r_spec.rb'
57
58
  end
58
59
  task :create_test2spec_dir do
59
60
  mkdir_p 'doc/output/tools' unless File.exist? 'doc/output/tools'
@@ -64,6 +65,7 @@ Spec::Rake::SpecTask.new('test2spec_test' => :test2spec) do |t|
64
65
  t.spec_files = FileList['spec/**/*_spec.rb']
65
66
  t.spec_opts = ["--format", "html", "--diff"]
66
67
  t.out = 'doc/output/tools/rspec_specs.html'
68
+ t.failure_message = "**** Translated specs failed. See doc/output/tools/rspec_specs.html ****"
67
69
  end
68
70
 
69
71
  desc 'Generate HTML documentation for website'
@@ -162,6 +164,20 @@ task :tag do
162
164
  puts "Done!"
163
165
  end
164
166
 
167
+ 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]
169
+
170
+ task :rails_pre_commit do
171
+ Dir.chdir 'vendor/rspec_on_rails' do
172
+ `rake pre_commit`
173
+ raise "RSpec on Rails pre_commit failed\ncd to vendor/rspec_on_rails and run rake pre_commit for more details" if $? != 0
174
+ end
175
+ end
176
+
177
+ task :commit_ok do |t|
178
+ puts "OK TO COMMIT"
179
+ end
180
+
165
181
  desc "Build the website with rdoc and rcov, but do not publish it"
166
182
  task :website => [:clobber, :rcov_verify, :webgen, :failing_examples_with_html, :test2spec_test, :examples_specdoc, :rdoc]
167
183
 
@@ -184,23 +200,14 @@ task :publish_website => [:verify_user, :website] do
184
200
  publisher.upload
185
201
  end
186
202
 
187
- desc "Build the Rails extension gem"
188
- task :package_rails do
189
- Dir.chdir 'vendor/rspec_on_rails/vendor/generators/rspec' do
190
- `rake clobber gem`
191
- raise "Failed to package RSpec on Rails" if $? != 0
192
- end
193
- end
194
-
195
203
  desc "Publish gem+tgz+zip on RubyForge. You must make sure lib/version.rb is aligned with the CHANGELOG file"
196
- task :publish_packages => [:verify_user, :verify_password, :package, :package_rails] do
204
+ task :publish_packages => [:verify_user, :verify_password, :package] do
197
205
  require 'meta_project'
198
206
  require 'rake/contrib/xforge'
199
207
  release_files = FileList[
200
208
  "pkg/#{PKG_FILE_NAME}.gem",
201
209
  "pkg/#{PKG_FILE_NAME}.tgz",
202
- "pkg/#{PKG_FILE_NAME}.zip",
203
- "vendor/rspec_on_rails/vendor/generators/rspec/pkg/rspec_generator-#{Spec::VERSION::STRING}.gem"
210
+ "pkg/#{PKG_FILE_NAME}.zip"
204
211
  ]
205
212
 
206
213
  Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |xf|
@@ -2,23 +2,33 @@ module Spec
2
2
  module Api
3
3
  # This module adds syntactic sugar that allows usage of should_* instead of should.*
4
4
  module Sugar
5
- alias_method :__orig_method_missing, :method_missing
6
- def method_missing(sym, *args, &block)
7
- if __is_sweetened? sym
8
- object = self
9
- calls = sym.to_s.split("_")
10
- while calls.length > 1
11
- call = calls.shift
12
- object = object.__send__(call)
13
- break if call == "be" unless ["an","a"].include? calls[0]
5
+ module SugarizeForRspec; end
6
+
7
+ def sugarize_for_rspec!
8
+ original_method_missing = instance_method(:method_missing)
9
+ class_eval do
10
+ include SugarizeForRspec # This is meant to add a signiture to the object that sugarization occurred.
11
+ def method_missing(sym, *args, &block)
12
+ _method_missing(sym, args, block)
13
+ end
14
+
15
+ define_method :_method_missing do |sym, args, block|
16
+ return original_method_missing.bind(self).call(sym, *args, &block) unless __is_sweetened?(sym)
17
+
18
+ object = self
19
+ calls = sym.to_s.split("_")
20
+ while calls.length > 1
21
+ call = calls.shift
22
+ object = object.__send__(call)
23
+ break if call == "be" unless ["an","a"].include? calls[0]
24
+ end
25
+ return object.__send__(calls.join("_"), *args, &block)
26
+ end
27
+
28
+ def __is_sweetened?(sym) #:nodoc:
29
+ return true if sym.to_s =~ /^should_/
14
30
  end
15
- return object.__send__(calls.join("_"), *args, &block)
16
31
  end
17
- __orig_method_missing(sym, *args, &block)
18
- end
19
-
20
- def __is_sweetened?(sym) #:nodoc:
21
- return true if sym.to_s =~ /^should_/
22
32
  end
23
33
  end
24
34
 
@@ -30,10 +40,12 @@ module Spec
30
40
  end
31
41
  end
32
42
 
33
- class Object #:nodoc:
43
+ class Module
34
44
  include Spec::Api::Sugar
35
45
  end
36
46
 
47
+ Object.sugarize_for_rspec!
48
+
37
49
  class Spec::Api::Mock #:nodoc:
38
50
  # NOTE: this resolves a bug caused by a conflict between Sugar#method_missing and Mock#method_missing, specifically
39
51
  # when the mock is set null_object=>true. It would be nice to get rid of this.
@@ -4,7 +4,6 @@
4
4
 
5
5
  require 'rake'
6
6
  require 'rake/tasklib'
7
- require File.dirname(__FILE__) + '/../../spec'
8
7
 
9
8
  module Spec
10
9
  module Rake
@@ -56,6 +55,9 @@ module Rake
56
55
  # Default is true
57
56
  attr_accessor :fail_on_error
58
57
 
58
+ # A message to print to stdout when there are failures. Useful if +out+ is used.
59
+ attr_accessor :failure_message
60
+
59
61
  # Explicitly define the list of spec files to be included in a
60
62
  # spec. +list+ is expected to be an array of file names (a
61
63
  # FileList is acceptable). If both +pattern+ and +spec_files+ are
@@ -105,7 +107,10 @@ module Rake
105
107
  file_prefix +
106
108
  specs.collect { |fn| "\"#{fn}\"" }.join(' ') +
107
109
  redirect
110
+
111
+ puts @failure_message if @failure_message && ($? != 0)
108
112
  rescue => e
113
+ puts @failure_message if @failure_message
109
114
  raise e if @fail_on_error
110
115
  end
111
116
  end
@@ -7,9 +7,14 @@ module Spec
7
7
 
8
8
  @context_eval_module = Module.new
9
9
  @context_eval_module.extend ContextEval::ModuleMethods
10
+ @context_eval_module.include ContextEval::InstanceMethods
11
+ before_context_eval
10
12
  @context_eval_module.class_eval &context_block
11
13
  end
12
14
 
15
+ def before_context_eval
16
+ end
17
+
13
18
  def inherit(klass)
14
19
  @context_eval_module.inherit klass
15
20
  end
@@ -68,8 +73,8 @@ module Spec
68
73
 
69
74
  protected
70
75
 
71
- def method_missing(method_name, *args)
72
- @context_eval_module.send(method_name, *args)
76
+ def method_missing(*args)
77
+ @context_eval_module.method_missing(*args)
73
78
  end
74
79
 
75
80
  def specifications
@@ -79,21 +84,21 @@ module Spec
79
84
  def setup_block
80
85
  @context_eval_module.send :setup_block
81
86
  end
82
- def setup_block=(value)
83
- @context_eval_module.send :setup_block=, value
84
- end
85
87
 
86
88
  def teardown_block
87
89
  @context_eval_module.send :teardown_block
88
90
  end
89
- def teardown_block=(value)
90
- @context_eval_module.send :teardown_block=, value
91
+
92
+ def setup_parts
93
+ @context_eval_module.send :setup_parts
94
+ end
95
+
96
+ def teardown_parts
97
+ @context_eval_module.send :teardown_parts
91
98
  end
92
99
 
93
100
  def prepare_execution_context_class
94
101
  weave_in_context_modules
95
- weave_in_setup_method
96
- weave_in_teardown_method
97
102
  execution_context_class
98
103
  end
99
104
 
@@ -108,30 +113,6 @@ module Spec
108
113
  end
109
114
  end
110
115
 
111
- def weave_in_setup_method
112
- if context_superclass.method_defined?(:setup)
113
- super_setup = context_superclass.instance_method(:setup)
114
- context_setup = setup_block if setup_block
115
-
116
- self.setup_block = proc do
117
- super_setup.bind(self).call
118
- instance_exec(&context_setup) if context_setup
119
- end
120
- end
121
- end
122
-
123
- def weave_in_teardown_method
124
- if context_superclass.method_defined?(:teardown)
125
- super_teardown = context_superclass.instance_method(:teardown)
126
- context_teardown = teardown_block if teardown_block
127
-
128
- self.teardown_block = proc do
129
- super_teardown.bind(self).call
130
- instance_exec(&context_teardown) if context_teardown
131
- end
132
- end
133
- end
134
-
135
116
  def context_modules
136
117
  @context_eval_module.send :context_modules
137
118
  end
@@ -1,14 +1,10 @@
1
- # Is this file really needed?
2
- # If I make this an empty file all tests are still passing.
3
- # But it seems to be used from other files.
4
- # Can we delete this file?
5
1
  module Spec
6
2
  module Runner
7
3
  module ContextEval
8
4
  module ModuleMethods
9
5
  def inherit(klass)
10
6
  @context_superclass = klass
11
- derive_execution_context_class_from context_superclass
7
+ derive_execution_context_class_from_context_superclass
12
8
  end
13
9
 
14
10
  def include(mod)
@@ -16,11 +12,11 @@ module Spec
16
12
  end
17
13
 
18
14
  def setup(&block)
19
- @setup_block = block
15
+ setup_parts << block
20
16
  end
21
17
 
22
18
  def teardown(&block)
23
- @teardown_block = block
19
+ teardown_parts << block
24
20
  end
25
21
 
26
22
  def specify(spec_name, &block)
@@ -35,8 +31,8 @@ module Spec
35
31
  protected
36
32
 
37
33
  def method_missing(method_name, *args)
38
- if context_superclass
39
- return context_superclass.send(method_name, *args)
34
+ if context_superclass.respond_to?(method_name)
35
+ return execution_context_class.send(method_name, *args)
40
36
  end
41
37
  super
42
38
  end
@@ -45,21 +41,63 @@ module Spec
45
41
  @specifications ||= []
46
42
  end
47
43
 
48
- attr_accessor :setup_block
49
- attr_accessor :teardown_block
44
+ def setup_parts
45
+ @setup_parts ||= []
46
+ end
50
47
 
51
- def derive_execution_context_class_from(context_superclass)
52
- @execution_context_class = Class.new(context_superclass)
53
- @execution_context_class.class_eval do
54
- include ::Spec::Runner::ExecutionContext::InstanceMethods
48
+ def teardown_parts
49
+ @teardown_parts ||= []
50
+ end
51
+
52
+ def setup_block
53
+ parts = setup_parts.dup
54
+
55
+ setup_method = begin
56
+ context_superclass.instance_method(:setup)
57
+ rescue
58
+ nil
59
+ end
60
+ parts.unshift setup_method if setup_method
61
+ create_block_from_parts(parts)
62
+ end
63
+
64
+ def teardown_block
65
+ parts = teardown_parts.dup
66
+
67
+ teardown_method = begin
68
+ context_superclass.instance_method(:teardown)
69
+ rescue
70
+ nil
71
+ end
72
+ parts.unshift teardown_method if teardown_method
73
+ create_block_from_parts(parts)
74
+ end
75
+
76
+ def create_block_from_parts(parts)
77
+ proc do
78
+ parts.each do |part|
79
+ if part.is_a?(UnboundMethod)
80
+ part.bind(self).call
81
+ else
82
+ instance_exec(&part)
83
+ end
84
+ end
55
85
  end
56
86
  end
57
87
 
58
88
  def execution_context_class
59
- @execution_context_class ||= begin
60
- derive_execution_context_class_from context_superclass
89
+ return @execution_context_class if @execution_context_class
90
+ derive_execution_context_class_from_context_superclass
91
+ @execution_context_class
92
+ end
93
+
94
+ def derive_execution_context_class_from_context_superclass
95
+ @execution_context_class = Class.new(context_superclass)
96
+ @execution_context_class.class_eval do
97
+ include ::Spec::Runner::ExecutionContext::InstanceMethods
61
98
  end
62
99
  end
100
+
63
101
  def context_superclass
64
102
  @context_superclass ||= Object
65
103
  end
@@ -68,6 +106,8 @@ module Spec
68
106
  @context_modules ||= []
69
107
  end
70
108
  end
109
+ module InstanceMethods
110
+ end
71
111
  end
72
112
  end
73
113
  end
@@ -10,32 +10,29 @@ module Spec
10
10
 
11
11
  def run(reporter=nil, setup_block=nil, teardown_block=nil, dry_run=false, execution_context=nil)
12
12
  reporter.spec_started(@name)
13
- if dry_run
14
- reporter.spec_finished(@name)
15
- else
16
- execution_context = ::Spec::Runner::ExecutionContext.new(self) unless execution_context
17
- errors = []
18
- begin
19
- execution_context.instance_exec(&setup_block) unless setup_block.nil?
20
- setup_ok = true
21
- execution_context.instance_exec(&@block)
22
- spec_ok = true
23
- rescue => e
24
- errors << e
25
- end
13
+ return reporter.spec_finished(@name) if dry_run
14
+ execution_context = execution_context || ::Spec::Runner::ExecutionContext.new(self)
15
+ errors = []
16
+ begin
17
+ execution_context.instance_exec(&setup_block) unless setup_block.nil?
18
+ setup_ok = true
19
+ execution_context.instance_exec(&@block)
20
+ spec_ok = true
21
+ rescue => e
22
+ errors << e
23
+ end
26
24
 
27
- begin
28
- execution_context.instance_exec(&teardown_block) unless teardown_block.nil?
29
- teardown_ok = true
30
- @mocks.each do |mock|
31
- mock.__verify
32
- end
33
- rescue => e
34
- errors << e
25
+ begin
26
+ execution_context.instance_exec(&teardown_block) unless teardown_block.nil?
27
+ teardown_ok = true
28
+ @mocks.each do |mock|
29
+ mock.__verify
35
30
  end
36
-
37
- reporter.spec_finished(@name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) unless reporter.nil?
31
+ rescue => e
32
+ errors << e
38
33
  end
34
+
35
+ reporter.spec_finished(@name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) unless reporter.nil?
39
36
  end
40
37
 
41
38
  def add_mock(mock)
@@ -4,7 +4,7 @@ require 'sexp_processor'
4
4
  module Spec
5
5
  module TestToSpec
6
6
  # Transforms a Sexp tree (produced by ParseTree) for a Test::Unit class
7
- # to an Sexp tree representing an RSpec context
7
+ # to a Sexp tree representing an RSpec context
8
8
  class SexpTransformer < SexpProcessor
9
9
  TRANSLATIONS = {
10
10
  :assert_equal => :should_equal,
@@ -57,22 +57,19 @@ module Spec
57
57
  context_body = []
58
58
  unless setup.empty?
59
59
  setup_block = process(setup.shift)
60
- unless methods.empty?
61
- translated_methods = []
62
- # At this stage we don't want to translate :lvar to :dvar
63
- @regular_method = true
64
- translated_methods << process(methods.shift) until methods.empty?
65
- @regular_method = false
66
- if setup_block.length == 3
67
- setup_block += translated_methods
68
- else
69
- setup_block[3] += translated_methods
70
- end
71
- end
72
60
  context_body << setup_block
73
61
  end
74
62
  context_body << process(teardown.shift) until teardown.empty?
75
63
  context_body << process(tests.shift) until tests.empty?
64
+
65
+ # At this stage we don't want to translate :lvar to :dvar
66
+ begin
67
+ @regular_method = true
68
+ context_body << process(methods.shift) until methods.empty?
69
+ ensure
70
+ @regular_method = false
71
+ end
72
+
76
73
  context_body << process(rest.shift) until rest.empty?
77
74
  exp.clear
78
75
 
data/lib/spec/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 15
6
+ TINY = 16
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
@@ -92,9 +92,9 @@ module Spec
92
92
  context "Fifth" do
93
93
  setup do
94
94
  one = 1
95
- def foo
96
- two = 2
97
- end
95
+ end
96
+ def foo
97
+ two = 2
98
98
  end
99
99
  end
100
100
  end
@@ -111,9 +111,10 @@ module Spec
111
111
  def wrapper
112
112
  context "Sixth" do
113
113
  setup do
114
- def foo
115
- two = 2
116
- end
114
+ end
115
+
116
+ def foo
117
+ two = 2
117
118
  end
118
119
  end
119
120
  end
@@ -128,9 +129,9 @@ module Spec
128
129
  def wrapper
129
130
  context "Seventh" do
130
131
  setup do
131
- def foo
132
- two = 2
133
- end
132
+ end
133
+ def foo
134
+ two = 2
134
135
  end
135
136
  end
136
137
  end
@@ -154,9 +155,6 @@ module Spec
154
155
  def wrapper
155
156
  context "Eighth" do
156
157
  setup do
157
- def foo
158
- two = 2
159
- end
160
158
  end
161
159
  teardown do
162
160
  torn = true
@@ -165,6 +163,9 @@ module Spec
165
163
  bar = foo
166
164
  bar.should_equal 2
167
165
  end
166
+ def foo
167
+ two = 2
168
+ end
168
169
  end
169
170
  end
170
171
  end
@@ -183,14 +184,14 @@ module Spec
183
184
  def wrapper
184
185
  context "Ninth" do
185
186
  setup do
186
- def assert_pair(n)
187
- (n%2).should_equal 0
188
- end
189
187
  end
190
188
  specify "2 should be pair" do
191
189
  foo = 1
192
190
  assert_pair(2)
193
191
  end
192
+ def assert_pair(n)
193
+ (n%2).should_equal 0
194
+ end
194
195
  end
195
196
  end
196
197
  end
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.15
7
- date: 2006-07-14 00:00:00 -05:00
8
- summary: RSpec-0.5.15 - BDD for Ruby http://rspec.rubyforge.org/
6
+ version: 0.5.16
7
+ date: 2006-07-31 00:00:00 -05:00
8
+ summary: RSpec-0.5.16 - BDD for Ruby http://rspec.rubyforge.org/
9
9
  require_paths:
10
10
  - lib
11
11
  email: rspec-devel@rubyforge.org