rspec-core 2.0.0.beta.1 → 2.0.0.beta.2
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/README.markdown +46 -28
- data/Rakefile +4 -4
- data/Upgrade.markdown +94 -0
- data/VERSION +1 -1
- data/example_specs/spec_helper.rb +1 -2
- data/lib/rspec/autorun.rb +1 -1
- data/lib/rspec/core.rb +0 -1
- data/lib/rspec/core/configuration.rb +29 -41
- data/lib/rspec/core/example_group.rb +11 -20
- data/lib/rspec/core/example_group_subject.rb +3 -3
- data/lib/rspec/core/formatters/documentation_formatter.rb +2 -2
- data/lib/rspec/core/{advice.rb → hooks.rb} +1 -1
- data/lib/rspec/core/let.rb +28 -0
- data/spec/rspec/core/configuration_spec.rb +3 -3
- data/spec/rspec/core/example_group_spec.rb +28 -28
- data/spec/rspec/core/example_group_subject_spec.rb +9 -8
- data/spec/rspec/core/shared_example_group_spec.rb +17 -11
- data/spec/spec_helper.rb +3 -6
- metadata +12 -13
- data/bin/autospec +0 -4
- data/example_specs/passing/simple_matcher_example.rb +0 -31
data/README.markdown
CHANGED
@@ -1,50 +1,68 @@
|
|
1
|
-
#
|
1
|
+
# Rspec Core
|
2
2
|
|
3
|
-
|
3
|
+
Rspec is an automated testing framework for Ruby, designed for use in Behaviour
|
4
|
+
Driven Development and Test Driven Development.
|
4
5
|
|
5
|
-
rspec-core
|
6
|
-
|
7
|
-
and or issues from outside the core development team, so please don't waste
|
8
|
-
your time until this notice changes.
|
6
|
+
rspec-core includes the Rspec runner, output formatters, and the `rspec`
|
7
|
+
command.
|
9
8
|
|
10
9
|
## Install
|
11
10
|
|
12
11
|
[sudo] gem install rspec --prerelease
|
13
12
|
|
14
|
-
This will install rspec, rspec-core, rspec-expectations and rspec-mocks
|
13
|
+
This will install the rspec, rspec-core, rspec-expectations and rspec-mocks
|
14
|
+
gems.
|
15
15
|
|
16
|
-
##
|
16
|
+
## Get Started
|
17
17
|
|
18
|
-
|
18
|
+
Start with a simple example of behavior you expect from your system. Do
|
19
|
+
this before you write any code:
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
class Foo
|
25
|
-
end
|
26
|
-
|
27
|
-
it "does something" do
|
28
|
-
Foo.new
|
21
|
+
# in spec/calculator_spec.rb
|
22
|
+
describe Calculator, "add" do
|
23
|
+
it "returns the sum of its arguments" do
|
24
|
+
Calculator.new.add(1, 2).should eq(3)
|
29
25
|
end
|
30
26
|
end
|
31
27
|
|
32
|
-
|
33
|
-
error in ruby-1.9. We had solved this in rspec-1.x, but rspec-2 has a slightly
|
34
|
-
different object model, so this has (for the moment) reared its ugly head. We'll
|
35
|
-
certainly resolve this before rspec-core-2.0.0 (final) is released.
|
28
|
+
Run this with the rspec command, and watch it fail:
|
36
29
|
|
37
|
-
|
30
|
+
$ rspec spec/calculator_spec.rb
|
31
|
+
./spec/calculator_spec.rb:1: uninitialized constant Calculator
|
38
32
|
|
39
|
-
|
40
|
-
class ::Foo
|
41
|
-
end
|
33
|
+
Implement the simplest solution:
|
42
34
|
|
43
|
-
|
44
|
-
|
35
|
+
# in lib/calculator.rb
|
36
|
+
class Calculator
|
37
|
+
def add(a,b)
|
38
|
+
a + b
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
42
|
+
Be sure to require the implementation file in the spec:
|
43
|
+
|
44
|
+
# in spec/calculator_spec.rb
|
45
|
+
# - Rspec adds ./lib to the $LOAD_PATH, so you can
|
46
|
+
# just require "calculator" directly
|
47
|
+
require "calculator"
|
48
|
+
|
49
|
+
Now run the spec again, and watch it pass:
|
50
|
+
|
51
|
+
$ rspec spec/calculator_spec.rb
|
52
|
+
.
|
53
|
+
|
54
|
+
Finished in 0.000315 seconds
|
55
|
+
1 example, 0 failures
|
56
|
+
|
57
|
+
Use the documentation formatter to see the resulting spec:
|
58
|
+
|
59
|
+
$ rspec spec/calculator_spec.rb --format doc
|
60
|
+
Calculator add
|
61
|
+
returns the sum of its arguments
|
62
|
+
|
63
|
+
Finished in 0.000379 seconds
|
64
|
+
1 example, 0 failures
|
65
|
+
|
48
66
|
#### Also see
|
49
67
|
|
50
68
|
* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
|
data/Rakefile
CHANGED
@@ -59,20 +59,20 @@ task :clobber do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
if RUBY_VERSION.to_f >= 1.9
|
62
|
-
Cucumber::Rake::Task.new
|
62
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
63
63
|
t.cucumber_opts = %w{--format progress}
|
64
64
|
end
|
65
65
|
|
66
|
-
task :default => [:check_dependencies, :spec, :
|
66
|
+
task :default => [:check_dependencies, :spec, :cucumber]
|
67
67
|
else
|
68
|
-
Cucumber::Rake::Task.new
|
68
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
69
69
|
t.rcov = true
|
70
70
|
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/*"]
|
71
71
|
t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
|
72
72
|
t.cucumber_opts = %w{--format progress}
|
73
73
|
end
|
74
74
|
|
75
|
-
task :default => [:check_dependencies, :rcov, :
|
75
|
+
task :default => [:check_dependencies, :rcov, :cucumber]
|
76
76
|
end
|
77
77
|
|
78
78
|
Rake::RDocTask.new do |rdoc|
|
data/Upgrade.markdown
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Upgrade to rspec-core-2.0
|
2
|
+
|
3
|
+
## What's changed
|
4
|
+
|
5
|
+
### Rspec namespace
|
6
|
+
|
7
|
+
The root namespace is now `Rspec` instead of `Spec`, and the root directory
|
8
|
+
under `lib` is `rspec` instead of `spec`.
|
9
|
+
|
10
|
+
### Configuration
|
11
|
+
|
12
|
+
Typically in `spec/spec_helper.rb`, configuration is now done like this:
|
13
|
+
|
14
|
+
Rspec.configure do |c|
|
15
|
+
# ....
|
16
|
+
end
|
17
|
+
|
18
|
+
### rspec commmand
|
19
|
+
|
20
|
+
The command to run specs is now `rspec` instead of `spec`.
|
21
|
+
|
22
|
+
rspec ./spec
|
23
|
+
|
24
|
+
## What's new
|
25
|
+
|
26
|
+
### Runner
|
27
|
+
|
28
|
+
The new runner for rspec-2 comes from Micronaut.
|
29
|
+
|
30
|
+
### Metadata!
|
31
|
+
|
32
|
+
In rspec-2, every example and example group comes with metadata information
|
33
|
+
like the file and line number on which it was declared, the arguments passed to
|
34
|
+
`describe` and `it`, etc. This metadata can be appended to through a hash
|
35
|
+
argument passed to `describe` or `it`, allowing us to pre and post-process
|
36
|
+
each example in a variety of ways.
|
37
|
+
|
38
|
+
The most obvious use is for filtering the run. For example:
|
39
|
+
|
40
|
+
# in spec/spec_helper.rb
|
41
|
+
Rspec.configure do |c|
|
42
|
+
c.filter_run :focus => true
|
43
|
+
end
|
44
|
+
|
45
|
+
# in any spec file
|
46
|
+
describe "something" do
|
47
|
+
it "does something", :focus => true do
|
48
|
+
# ....
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
When you run the `rspec` command, rspec will run only the examples that have
|
53
|
+
`:focus => true` in the hash.
|
54
|
+
|
55
|
+
You can also add `run_all_when_everything_filtered` to the config:
|
56
|
+
|
57
|
+
Rspec.configure do |c|
|
58
|
+
c.filter_run :focus => true
|
59
|
+
c.run_all_when_everything_filtered = true
|
60
|
+
end
|
61
|
+
|
62
|
+
Now if there are no examples tagged with `:focus => true`, all examples
|
63
|
+
will be run. This makes it really easy to focus on one example for a
|
64
|
+
while, but then go back to running all of the examples by removing that
|
65
|
+
argument from `it`. Works with `describe` too, in which case it runs
|
66
|
+
all of the examples in that group.
|
67
|
+
|
68
|
+
The configuration will accept a lambda, which provides a lot of flexibility
|
69
|
+
in filtering examples. Say, for example, you have a spec for functionality that
|
70
|
+
behaves slightly differently in Ruby 1.8 and Ruby 1.9. We have that in
|
71
|
+
rspec-core, and here's how we're getting the right stuff to run under the
|
72
|
+
right version:
|
73
|
+
|
74
|
+
# in spec/spec_helper.rb
|
75
|
+
Rspec.configure do |c|
|
76
|
+
c.exclusion_filter = { :ruby => lambda {|version|
|
77
|
+
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
|
78
|
+
}}
|
79
|
+
end
|
80
|
+
|
81
|
+
# in any spec file
|
82
|
+
describe "something" do
|
83
|
+
it "does something", :ruby => 1.8 do
|
84
|
+
# ....
|
85
|
+
end
|
86
|
+
|
87
|
+
it "does something", :ruby => 1.9 do
|
88
|
+
# ....
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
In this case, we're using `exclusion_filter` instead of `filter_run` or
|
93
|
+
`filter`, which indicate _inclusion_ filters. So each of those examples is
|
94
|
+
excluded if we're _not_ running the version of Ruby they work with.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.beta.
|
1
|
+
2.0.0.beta.2
|
@@ -2,10 +2,9 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
2
|
$LOAD_PATH << File.expand_path('../../../rspec-expectations/lib', __FILE__)
|
3
3
|
$LOAD_PATH << File.expand_path('../../../rspec-mocks/lib', __FILE__)
|
4
4
|
require 'rspec/expectations'
|
5
|
-
require 'rspec/
|
5
|
+
require 'rspec/core'
|
6
6
|
|
7
7
|
Rspec.configure do |c|
|
8
8
|
c.mock_with :rspec
|
9
|
-
c.include Rspec::Matchers
|
10
9
|
end
|
11
10
|
|
data/lib/rspec/autorun.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'rspec/core'
|
2
|
-
Rspec::Core.
|
2
|
+
Rspec::Core::Runner.autorun
|
data/lib/rspec/core.rb
CHANGED
@@ -7,7 +7,6 @@ require 'rspec/core/configuration'
|
|
7
7
|
require 'rspec/core/command_line_options'
|
8
8
|
require 'rspec/core/runner'
|
9
9
|
require 'rspec/core/example'
|
10
|
-
require 'rspec/core/metadata'
|
11
10
|
require 'rspec/core/kernel_extensions'
|
12
11
|
require 'rspec/core/shared_example_group'
|
13
12
|
require 'rspec/core/example_group_subject'
|
@@ -1,26 +1,18 @@
|
|
1
1
|
module Rspec
|
2
2
|
module Core
|
3
3
|
class Configuration
|
4
|
-
#
|
5
|
-
|
4
|
+
# Control what examples are run by filtering
|
5
|
+
attr_accessor :filter
|
6
6
|
|
7
|
-
#
|
8
|
-
|
7
|
+
# Control what examples are not run by filtering
|
8
|
+
attr_accessor :exclusion_filter
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
# Modules that will be included or extended based on given filters
|
13
|
-
attr_reader :include_or_extend_modules
|
14
|
-
|
15
|
-
# Run all examples if the run is filtered, and no examples were found. Normally this is what you want -
|
16
|
-
# when using focused examples for instance. Defaults to true
|
17
|
-
attr_accessor :run_all_when_everything_filtered
|
18
|
-
|
19
|
-
attr_reader :options
|
10
|
+
# Run all examples if the run is filtered, and no examples were found.
|
11
|
+
attr_writer :run_all_when_everything_filtered
|
20
12
|
|
21
13
|
def initialize
|
22
14
|
@run_all_when_everything_filtered = false
|
23
|
-
@
|
15
|
+
@hooks = {
|
24
16
|
:before => { :each => [], :all => [], :suite => [] },
|
25
17
|
:after => { :each => [], :all => [], :suite => [] }
|
26
18
|
}
|
@@ -47,15 +39,15 @@ module Rspec
|
|
47
39
|
end
|
48
40
|
|
49
41
|
def cleaned_from_backtrace?(line)
|
50
|
-
options[:backtrace_clean_patterns].any? { |regex| line =~ regex }
|
42
|
+
@options[:backtrace_clean_patterns].any? { |regex| line =~ regex }
|
51
43
|
end
|
52
44
|
|
53
45
|
def backtrace_clean_patterns
|
54
|
-
options[:backtrace_clean_patterns]
|
46
|
+
@options[:backtrace_clean_patterns]
|
55
47
|
end
|
56
48
|
|
57
49
|
def mock_framework=(use_me_to_mock)
|
58
|
-
options[:mock_framework] = use_me_to_mock
|
50
|
+
@options[:mock_framework] = use_me_to_mock
|
59
51
|
|
60
52
|
mock_framework_class = case use_me_to_mock.to_s
|
61
53
|
when /rspec/i
|
@@ -75,24 +67,24 @@ module Rspec
|
|
75
67
|
Rspec::Core::Mocking::WithAbsolutelyNothing
|
76
68
|
end
|
77
69
|
|
78
|
-
options[:mock_framework_class] = mock_framework_class
|
70
|
+
@options[:mock_framework_class] = mock_framework_class
|
79
71
|
Rspec::Core::ExampleGroup.send(:include, mock_framework_class)
|
80
72
|
end
|
81
73
|
|
82
74
|
def mock_framework
|
83
|
-
options[:mock_framework]
|
75
|
+
@options[:mock_framework]
|
84
76
|
end
|
85
77
|
|
86
78
|
def filename_pattern
|
87
|
-
options[:filename_pattern]
|
79
|
+
@options[:filename_pattern]
|
88
80
|
end
|
89
81
|
|
90
82
|
def filename_pattern=(new_pattern)
|
91
|
-
options[:filename_pattern] = new_pattern
|
83
|
+
@options[:filename_pattern] = new_pattern
|
92
84
|
end
|
93
85
|
|
94
86
|
def color_enabled=(on_or_off)
|
95
|
-
options[:color_enabled] = on_or_off
|
87
|
+
@options[:color_enabled] = on_or_off
|
96
88
|
end
|
97
89
|
|
98
90
|
def full_backtrace=(bool)
|
@@ -118,7 +110,7 @@ EOM
|
|
118
110
|
end
|
119
111
|
|
120
112
|
def color_enabled?
|
121
|
-
options[:color_enabled]
|
113
|
+
@options[:color_enabled]
|
122
114
|
end
|
123
115
|
|
124
116
|
def line_number=(line_number)
|
@@ -131,15 +123,15 @@ EOM
|
|
131
123
|
|
132
124
|
# Enable profiling of example run - defaults to false
|
133
125
|
def profile_examples
|
134
|
-
options[:profile_examples]
|
126
|
+
@options[:profile_examples]
|
135
127
|
end
|
136
128
|
|
137
129
|
def profile_examples=(on_or_off)
|
138
|
-
options[:profile_examples] = on_or_off
|
130
|
+
@options[:profile_examples] = on_or_off
|
139
131
|
end
|
140
132
|
|
141
133
|
def formatter_class
|
142
|
-
options[:formatter_class]
|
134
|
+
@options[:formatter_class]
|
143
135
|
end
|
144
136
|
|
145
137
|
def formatter=(formatter_to_use)
|
@@ -151,7 +143,7 @@ EOM
|
|
151
143
|
else
|
152
144
|
raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?."
|
153
145
|
end
|
154
|
-
options[:formatter_class] = formatter_class
|
146
|
+
@options[:formatter_class] = formatter_class
|
155
147
|
end
|
156
148
|
|
157
149
|
def formatter
|
@@ -159,11 +151,11 @@ EOM
|
|
159
151
|
end
|
160
152
|
|
161
153
|
def files_to_run
|
162
|
-
options[:files_to_run]
|
154
|
+
@options[:files_to_run]
|
163
155
|
end
|
164
156
|
|
165
157
|
def files_or_directories_to_run=(*files)
|
166
|
-
options[:files_to_run] = files.flatten.inject([]) do |result, file|
|
158
|
+
@options[:files_to_run] = files.flatten.inject([]) do |result, file|
|
167
159
|
if File.directory?(file)
|
168
160
|
filename_pattern.split(",").each do |pattern|
|
169
161
|
result += Dir["#{file}/#{pattern.strip}"]
|
@@ -183,10 +175,6 @@ EOM
|
|
183
175
|
Rspec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
|
184
176
|
end
|
185
177
|
|
186
|
-
def autorun!
|
187
|
-
Rspec::Core::Runner.autorun
|
188
|
-
end
|
189
|
-
|
190
178
|
def filter_run(options={})
|
191
179
|
@filter = options unless @filter and @filter[:line_number] || @filter[:full_description]
|
192
180
|
end
|
@@ -209,29 +197,29 @@ EOM
|
|
209
197
|
end
|
210
198
|
|
211
199
|
def include(mod, options={})
|
212
|
-
include_or_extend_modules << [:include, mod, options]
|
200
|
+
@include_or_extend_modules << [:include, mod, options]
|
213
201
|
end
|
214
202
|
|
215
203
|
def extend(mod, options={})
|
216
|
-
include_or_extend_modules << [:extend, mod, options]
|
204
|
+
@include_or_extend_modules << [:extend, mod, options]
|
217
205
|
end
|
218
206
|
|
219
207
|
def find_modules(group)
|
220
|
-
include_or_extend_modules.select do |include_or_extend, mod, filters|
|
208
|
+
@include_or_extend_modules.select do |include_or_extend, mod, filters|
|
221
209
|
group.all_apply?(filters)
|
222
210
|
end
|
223
211
|
end
|
224
212
|
|
225
213
|
def before(each_or_all=:each, options={}, &block)
|
226
|
-
|
214
|
+
@hooks[:before][each_or_all] << [options, block]
|
227
215
|
end
|
228
216
|
|
229
217
|
def after(each_or_all=:each, options={}, &block)
|
230
|
-
|
218
|
+
@hooks[:after][each_or_all] << [options, block]
|
231
219
|
end
|
232
220
|
|
233
|
-
def
|
234
|
-
|
221
|
+
def find_hook(hook, each_or_all, group)
|
222
|
+
@hooks[hook][each_or_all].select do |filters, block|
|
235
223
|
group.all_apply?(filters)
|
236
224
|
end.map { |filters, block| block }
|
237
225
|
end
|
@@ -1,18 +1,19 @@
|
|
1
|
-
require 'rspec/core/
|
1
|
+
require 'rspec/core/hooks'
|
2
2
|
require 'rspec/core/example_group_subject'
|
3
|
+
require 'rspec/core/let'
|
3
4
|
require 'rspec/core/metadata'
|
4
5
|
|
5
6
|
module Rspec
|
6
7
|
module Core
|
7
8
|
class ExampleGroup
|
8
|
-
extend
|
9
|
+
extend Hooks
|
9
10
|
include ExampleGroupSubject
|
11
|
+
include Let
|
10
12
|
|
11
13
|
attr_accessor :running_example
|
12
14
|
|
13
15
|
def self.inherited(klass)
|
14
|
-
|
15
|
-
Rspec::Core.configuration.autorun!
|
16
|
+
Rspec::Core::Runner.autorun
|
16
17
|
Rspec::Core.world.example_groups << klass
|
17
18
|
end
|
18
19
|
|
@@ -83,8 +84,8 @@ module Rspec
|
|
83
84
|
@metadata
|
84
85
|
end
|
85
86
|
|
86
|
-
def self.
|
87
|
-
|
87
|
+
def self.display_name
|
88
|
+
metadata[:example_group][:name]
|
88
89
|
end
|
89
90
|
|
90
91
|
def self.description
|
@@ -155,26 +156,26 @@ module Rspec
|
|
155
156
|
if superclass.respond_to?(:before_all_ivars)
|
156
157
|
superclass.before_all_ivars.each { |ivar, val| running_example.instance_variable_set(ivar, val) }
|
157
158
|
end
|
158
|
-
configuration.
|
159
|
+
configuration.find_hook(:before, :all, self).each { |blk| running_example.instance_eval(&blk) }
|
159
160
|
|
160
161
|
before_alls.each { |blk| running_example.instance_eval(&blk) }
|
161
162
|
running_example.instance_variables.each { |ivar| before_all_ivars[ivar] = running_example.instance_variable_get(ivar) }
|
162
163
|
end
|
163
164
|
|
164
165
|
def self.eval_before_eachs(running_example)
|
165
|
-
configuration.
|
166
|
+
configuration.find_hook(:before, :each, self).each { |blk| running_example.instance_eval(&blk) }
|
166
167
|
before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_example.instance_eval(&blk) } }
|
167
168
|
end
|
168
169
|
|
169
170
|
def self.eval_after_alls(running_example)
|
170
171
|
after_alls.each { |blk| running_example.instance_eval(&blk) }
|
171
|
-
configuration.
|
172
|
+
configuration.find_hook(:after, :all, self).each { |blk| running_example.instance_eval(&blk) }
|
172
173
|
before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_example.instance_variable_get(ivar) }
|
173
174
|
end
|
174
175
|
|
175
176
|
def self.eval_after_eachs(running_example)
|
176
177
|
after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_example.instance_eval(&blk) } }
|
177
|
-
configuration.
|
178
|
+
configuration.find_hook(:after, :each, self).each { |blk| running_example.instance_eval(&blk) }
|
178
179
|
end
|
179
180
|
|
180
181
|
def self.run(reporter)
|
@@ -201,12 +202,6 @@ module Rspec
|
|
201
202
|
self == Rspec::Core::ExampleGroup ? 'Rspec::Core::ExampleGroup' : name
|
202
203
|
end
|
203
204
|
|
204
|
-
def self.let(name, &block)
|
205
|
-
define_method(name) do
|
206
|
-
__memoized[name] ||= instance_eval(&block)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
205
|
def self.all_apply?(filters)
|
211
206
|
metadata.all_apply?(filters)
|
212
207
|
end
|
@@ -215,10 +210,6 @@ module Rspec
|
|
215
210
|
self.class.describes
|
216
211
|
end
|
217
212
|
|
218
|
-
def __memoized
|
219
|
-
@__memoized ||= {}
|
220
|
-
end
|
221
|
-
|
222
213
|
def __reset__
|
223
214
|
instance_variables.each { |ivar| remove_instance_variable(ivar) }
|
224
215
|
__memoized.clear
|
@@ -3,9 +3,9 @@ module Rspec
|
|
3
3
|
module ExampleGroupSubject
|
4
4
|
|
5
5
|
def self.included(kls)
|
6
|
-
kls.extend
|
7
|
-
kls.
|
8
|
-
kls.
|
6
|
+
kls.extend ClassMethods
|
7
|
+
kls.__send__ :alias_method, :__should_for_example_group__, :should
|
8
|
+
kls.__send__ :alias_method, :__should_not_for_example_group__, :should_not
|
9
9
|
end
|
10
10
|
|
11
11
|
def subject
|
@@ -17,7 +17,7 @@ module Rspec
|
|
17
17
|
described_example_group_chain.each_with_index do |nested_example_group, i|
|
18
18
|
unless nested_example_group == @previous_nested_example_groups[i]
|
19
19
|
at_root_level = (i == 0)
|
20
|
-
desc_or_name = at_root_level ? nested_example_group.
|
20
|
+
desc_or_name = at_root_level ? nested_example_group.display_name : nested_example_group.description
|
21
21
|
output.puts if at_root_level
|
22
22
|
output.puts "#{' ' * i}#{desc_or_name}"
|
23
23
|
end
|
@@ -79,4 +79,4 @@ module Rspec
|
|
79
79
|
|
80
80
|
end
|
81
81
|
|
82
|
-
end
|
82
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rspec
|
2
|
+
module Core
|
3
|
+
|
4
|
+
module Let
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def let(name, &block)
|
8
|
+
define_method(name) do
|
9
|
+
__memoized[name] ||= instance_eval(&block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
def __memoized
|
16
|
+
@__memoized ||= {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(mod)
|
21
|
+
mod.extend ClassMethods
|
22
|
+
mod.__send__ :include, InstanceMethods
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -164,10 +164,10 @@ module Rspec::Core
|
|
164
164
|
|
165
165
|
end
|
166
166
|
|
167
|
-
describe "run_all_when_everything_filtered" do
|
167
|
+
describe "run_all_when_everything_filtered?" do
|
168
168
|
|
169
169
|
it "defaults to false" do
|
170
|
-
config.run_all_when_everything_filtered
|
170
|
+
config.run_all_when_everything_filtered?.should == false
|
171
171
|
end
|
172
172
|
|
173
173
|
it "can be queried with question method" do
|
@@ -213,7 +213,7 @@ module Rspec::Core
|
|
213
213
|
describe "full_backtrace=" do
|
214
214
|
it "clears the backtrace clean patterns" do
|
215
215
|
config.full_backtrace = true
|
216
|
-
config.
|
216
|
+
config.backtrace_clean_patterns.should == []
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
@@ -1,5 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class SelfObserver
|
4
|
+
def self.cache
|
5
|
+
@cache ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.class.cache << self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
module Rspec::Core
|
4
14
|
|
5
15
|
describe ExampleGroup do
|
@@ -16,25 +26,25 @@ module Rspec::Core
|
|
16
26
|
|
17
27
|
end
|
18
28
|
|
19
|
-
describe '#
|
29
|
+
describe '#display_name' do
|
20
30
|
|
21
31
|
it "uses the first parameter as name" do
|
22
|
-
ExampleGroup.create("my favorite pony") { }.
|
32
|
+
ExampleGroup.create("my favorite pony") { }.display_name.should == 'my favorite pony'
|
23
33
|
end
|
24
34
|
|
25
35
|
it "accepts a constant as the first parameter" do
|
26
|
-
ExampleGroup.create(Object) { }.
|
36
|
+
ExampleGroup.create(Object) { }.display_name.should == 'Object'
|
27
37
|
end
|
28
38
|
|
29
39
|
it "concats nested names" do
|
30
40
|
group = ExampleGroup.create(Object, 'test') {}
|
31
|
-
group.
|
41
|
+
group.display_name.should == 'Object test'
|
32
42
|
|
33
43
|
nested_group_one = group.describe('nested one') { }
|
34
|
-
nested_group_one.
|
44
|
+
nested_group_one.display_name.should == 'Object test nested one'
|
35
45
|
|
36
46
|
nested_group_two = nested_group_one.describe('nested two') { }
|
37
|
-
nested_group_two.
|
47
|
+
nested_group_two.display_name.should == 'Object test nested one nested two'
|
38
48
|
end
|
39
49
|
|
40
50
|
end
|
@@ -290,13 +300,12 @@ module Rspec::Core
|
|
290
300
|
@before_all_top_level.should == 'before_all_top_level'
|
291
301
|
end
|
292
302
|
|
293
|
-
it "should be able to access the before all ivars in the before_all_ivars hash" do
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
end
|
303
|
+
it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
|
304
|
+
running_example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should be able to access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
|
308
|
+
running_example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
|
300
309
|
end
|
301
310
|
|
302
311
|
describe "but now I am nested" do
|
@@ -356,28 +365,19 @@ module Rspec::Core
|
|
356
365
|
end
|
357
366
|
|
358
367
|
describe "#around" do
|
359
|
-
class Thing
|
360
|
-
def self.cache
|
361
|
-
@cache ||= []
|
362
|
-
end
|
363
|
-
|
364
|
-
def initialize
|
365
|
-
self.class.cache << self
|
366
|
-
end
|
367
|
-
end
|
368
368
|
|
369
369
|
around(:each) do |example|
|
370
|
-
|
370
|
+
SelfObserver.new
|
371
371
|
example.run
|
372
|
-
|
372
|
+
SelfObserver.cache.clear
|
373
373
|
end
|
374
374
|
|
375
|
-
it "has 1
|
376
|
-
|
375
|
+
it "has 1 SelfObserver (1)" do
|
376
|
+
SelfObserver.cache.length.should == 1
|
377
377
|
end
|
378
378
|
|
379
|
-
it "has 1
|
380
|
-
|
379
|
+
it "has 1 SelfObserver (2)" do
|
380
|
+
SelfObserver.cache.length.should == 1
|
381
381
|
end
|
382
382
|
end
|
383
383
|
end
|
@@ -31,7 +31,7 @@ module Rspec::Core
|
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
describe "explicit subject" do
|
35
35
|
describe "defined in a top level group" do
|
36
36
|
it "replaces the implicit subject in that group" do
|
37
37
|
group = ExampleGroup.create(Array)
|
@@ -41,19 +41,20 @@ module Rspec::Core
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "defined in a top level group" do
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
let(:group) do
|
45
|
+
ExampleGroup.create do
|
46
|
+
subject{ [4,5,6] }
|
47
|
+
end
|
47
48
|
end
|
48
49
|
|
49
50
|
it "is available in a nested group (subclass)" do
|
50
|
-
|
51
|
-
|
51
|
+
nested_group = group.describe("I'm nested!") { }
|
52
|
+
nested_group.subject.call.should == [4,5,6]
|
52
53
|
end
|
53
54
|
|
54
55
|
it "is available in a doubly nested group (subclass)" do
|
55
|
-
nested_group =
|
56
|
-
doubly_nested_group = nested_group.describe("Nesting level
|
56
|
+
nested_group = group.describe("Nesting level 1") { }
|
57
|
+
doubly_nested_group = nested_group.describe("Nesting level 2") { }
|
57
58
|
doubly_nested_group.subject.call.should == [4,5,6]
|
58
59
|
end
|
59
60
|
end
|
@@ -41,7 +41,7 @@ module Rspec::Core
|
|
41
41
|
Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
|
42
42
|
end
|
43
43
|
|
44
|
-
it "should make any shared example_group available at the correct level" do
|
44
|
+
it "should make any shared example_group available at the correct level", :ruby => 1.8 do
|
45
45
|
group = ExampleGroup.create('fake group')
|
46
46
|
block = lambda {
|
47
47
|
def self.class_helper; end
|
@@ -49,14 +49,20 @@ module Rspec::Core
|
|
49
49
|
}
|
50
50
|
Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
|
51
51
|
group.it_should_behave_like :shared_example_group
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
group.instance_methods.should include('extra_helper')
|
53
|
+
group.singleton_methods.should include('class_helper')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should make any shared example_group available at the correct level", :ruby => 1.9 do
|
57
|
+
group = ExampleGroup.create('fake group')
|
58
|
+
block = lambda {
|
59
|
+
def self.class_helper; end
|
60
|
+
def extra_helper; end
|
61
|
+
}
|
62
|
+
Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
|
63
|
+
group.it_should_behave_like :shared_example_group
|
64
|
+
group.instance_methods.should include(:extra_helper)
|
65
|
+
group.singleton_methods.should include(:class_helper)
|
60
66
|
end
|
61
67
|
|
62
68
|
it "should raise when named shared example_group can not be found"
|
@@ -82,8 +88,8 @@ module Rspec::Core
|
|
82
88
|
|
83
89
|
it "adds examples to from two shared groups" do
|
84
90
|
cleanup_shared_example_groups do
|
85
|
-
group = ExampleGroup.create("example_group") do
|
86
|
-
|
91
|
+
group = ExampleGroup.create("example_group") do
|
92
|
+
it("i was already here") {}
|
87
93
|
end
|
88
94
|
|
89
95
|
group.examples.size.should == 1
|
data/spec/spec_helper.rb
CHANGED
@@ -8,10 +8,6 @@ require 'rspec/mocks'
|
|
8
8
|
|
9
9
|
Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
|
10
10
|
|
11
|
-
def with_ruby(version)
|
12
|
-
yield if RUBY_VERSION.to_s =~ Regexp.compile("^#{version}")
|
13
|
-
end
|
14
|
-
|
15
11
|
module Rspec
|
16
12
|
module Core
|
17
13
|
module Matchers
|
@@ -40,7 +36,8 @@ end
|
|
40
36
|
|
41
37
|
Rspec.configure do |c|
|
42
38
|
c.mock_framework = :rspec
|
43
|
-
c.filter_run :focused => true
|
44
|
-
c.run_all_when_everything_filtered = true
|
45
39
|
c.color_enabled = !in_editor?
|
40
|
+
c.exclusion_filter = { :ruby => lambda {|version|
|
41
|
+
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
|
42
|
+
}}
|
46
43
|
end
|
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 2.0.0.beta.
|
10
|
+
- 2
|
11
|
+
version: 2.0.0.beta.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Chad Humphries
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-03-
|
20
|
+
date: 2010-03-04 00:00:00 -06:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -32,8 +32,8 @@ dependencies:
|
|
32
32
|
- 0
|
33
33
|
- 0
|
34
34
|
- beta
|
35
|
-
-
|
36
|
-
version: 2.0.0.beta.
|
35
|
+
- 2
|
36
|
+
version: 2.0.0.beta.2
|
37
37
|
type: :development
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
@@ -48,8 +48,8 @@ dependencies:
|
|
48
48
|
- 0
|
49
49
|
- 0
|
50
50
|
- beta
|
51
|
-
-
|
52
|
-
version: 2.0.0.beta.
|
51
|
+
- 2
|
52
|
+
version: 2.0.0.beta.2
|
53
53
|
type: :development
|
54
54
|
version_requirements: *id002
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -69,7 +69,6 @@ dependencies:
|
|
69
69
|
description: Rspec runner and example group classes
|
70
70
|
email: dchelimsky@gmail.com;chad.humphries@gmail.com
|
71
71
|
executables:
|
72
|
-
- autospec
|
73
72
|
- rspec
|
74
73
|
- spec
|
75
74
|
extensions: []
|
@@ -84,8 +83,8 @@ files:
|
|
84
83
|
- README.markdown
|
85
84
|
- Rakefile
|
86
85
|
- TODO.markdown
|
86
|
+
- Upgrade.markdown
|
87
87
|
- VERSION
|
88
|
-
- bin/autospec
|
89
88
|
- bin/rspec
|
90
89
|
- bin/spec
|
91
90
|
- cucumber.yml
|
@@ -128,7 +127,6 @@ files:
|
|
128
127
|
- example_specs/passing/predicate_example.rb
|
129
128
|
- example_specs/passing/shared_example_group_example.rb
|
130
129
|
- example_specs/passing/shared_stack_examples.rb
|
131
|
-
- example_specs/passing/simple_matcher_example.rb
|
132
130
|
- example_specs/passing/spec_helper.rb
|
133
131
|
- example_specs/passing/stack.rb
|
134
132
|
- example_specs/passing/stack_spec.rb
|
@@ -172,7 +170,6 @@ files:
|
|
172
170
|
- features/support/env.rb
|
173
171
|
- lib/rspec/autorun.rb
|
174
172
|
- lib/rspec/core.rb
|
175
|
-
- lib/rspec/core/advice.rb
|
176
173
|
- lib/rspec/core/around_proxy.rb
|
177
174
|
- lib/rspec/core/backward_compatibility.rb
|
178
175
|
- lib/rspec/core/command_line_options.rb
|
@@ -186,7 +183,9 @@ files:
|
|
186
183
|
- lib/rspec/core/formatters/base_text_formatter.rb
|
187
184
|
- lib/rspec/core/formatters/documentation_formatter.rb
|
188
185
|
- lib/rspec/core/formatters/progress_formatter.rb
|
186
|
+
- lib/rspec/core/hooks.rb
|
189
187
|
- lib/rspec/core/kernel_extensions.rb
|
188
|
+
- lib/rspec/core/let.rb
|
190
189
|
- lib/rspec/core/load_path.rb
|
191
190
|
- lib/rspec/core/metadata.rb
|
192
191
|
- lib/rspec/core/mocking/with_absolutely_nothing.rb
|
@@ -234,7 +233,7 @@ licenses: []
|
|
234
233
|
post_install_message: |
|
235
234
|
**************************************************
|
236
235
|
|
237
|
-
Thank you for installing rspec-core-2.0.0.beta.
|
236
|
+
Thank you for installing rspec-core-2.0.0.beta.2
|
238
237
|
|
239
238
|
This is beta software. If you are looking
|
240
239
|
for a supported production release, please
|
@@ -268,7 +267,7 @@ rubyforge_project: rspec
|
|
268
267
|
rubygems_version: 1.3.6
|
269
268
|
signing_key:
|
270
269
|
specification_version: 3
|
271
|
-
summary: rspec-core-2.0.0.beta.
|
270
|
+
summary: rspec-core-2.0.0.beta.2
|
272
271
|
test_files:
|
273
272
|
- spec/rspec/core/command_line_options_spec.rb
|
274
273
|
- spec/rspec/core/configuration_spec.rb
|
data/bin/autospec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe "arrays" do
|
4
|
-
def contain_same_elements_as(expected)
|
5
|
-
simple_matcher "array with same elements in any order as #{expected.inspect}" do |actual|
|
6
|
-
if actual.size == expected.size
|
7
|
-
a, e = actual.dup, expected.dup
|
8
|
-
until e.empty? do
|
9
|
-
if i = a.index(e.pop) then a.delete_at(i) end
|
10
|
-
end
|
11
|
-
a.empty?
|
12
|
-
else
|
13
|
-
false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "can be matched by their contents disregarding order" do
|
19
|
-
subject { [1,2,2,3] }
|
20
|
-
it { should contain_same_elements_as([1,2,2,3]) }
|
21
|
-
it { should contain_same_elements_as([2,3,2,1]) }
|
22
|
-
it { should_not contain_same_elements_as([3,3,2,1]) }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "fail the match with different contents" do
|
26
|
-
subject { [1,2,3] }
|
27
|
-
it { should_not contain_same_elements_as([2,3,4])}
|
28
|
-
it { should_not contain_same_elements_as([1,2,2,3])}
|
29
|
-
it { should_not contain_same_elements_as([1,2])}
|
30
|
-
end
|
31
|
-
end
|