rspec-core 2.0.0.a2 → 2.0.0.a3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -2
- data/.gitignore +1 -0
- data/README.markdown +18 -4
- data/Rakefile +6 -17
- data/bin/rspec +0 -8
- data/example_specs/failing/README.txt +1 -1
- data/example_specs/failing/spec_helper.rb +7 -2
- data/example_specs/failing/team_spec.rb +0 -1
- data/features/before_and_after_blocks/around.feature +2 -0
- data/features/command_line/example_name_option.feature +54 -0
- data/features/command_line/line_number_appended_to_path.feature +39 -0
- data/features/command_line/line_number_option.feature +40 -0
- data/features/matchers/define_matcher.feature +18 -4
- data/features/matchers/define_matcher_outside_rspec.feature +1 -2
- data/features/mocks/mix_stubs_and_mocks.feature +2 -0
- data/features/subject/explicit_subject.feature +4 -0
- data/features/subject/implicit_subject.feature +4 -0
- data/features/support/env.rb +15 -1
- data/lib/rspec/core.rb +1 -1
- data/lib/rspec/core/command_line_options.rb +9 -0
- data/lib/rspec/core/configuration.rb +18 -8
- data/lib/rspec/core/example.rb +14 -23
- data/lib/rspec/core/example_group.rb +39 -30
- data/lib/rspec/core/formatters/base_formatter.rb +9 -7
- data/lib/rspec/core/formatters/base_text_formatter.rb +2 -2
- data/lib/rspec/core/formatters/documentation_formatter.rb +10 -12
- data/lib/rspec/core/kernel_extensions.rb +2 -2
- data/lib/rspec/core/load_path.rb +1 -2
- data/lib/rspec/core/metadata.rb +65 -27
- data/lib/rspec/core/ruby_project.rb +24 -10
- data/lib/rspec/core/runner.rb +3 -3
- data/lib/rspec/core/{shared_behaviour.rb → shared_example_group.rb} +5 -5
- data/lib/rspec/core/{shared_behaviour_kernel_extensions.rb → shared_example_group_kernel_extensions.rb} +3 -3
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +29 -50
- data/rspec-core.gemspec +22 -21
- data/spec/rspec/core/command_line_options_spec.rb +14 -0
- data/spec/rspec/core/configuration_spec.rb +51 -13
- data/spec/rspec/core/example_group_spec.rb +61 -68
- data/spec/rspec/core/example_group_subject_spec.rb +1 -1
- data/spec/rspec/core/example_spec.rb +19 -8
- data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -2
- data/spec/rspec/core/metadata_spec.rb +52 -17
- data/spec/rspec/core/mocha_spec.rb +4 -4
- data/spec/rspec/core/pending_example_spec.rb +19 -0
- data/spec/rspec/core/ruby_project_spec.rb +24 -0
- data/spec/rspec/core/{shared_behaviour_spec.rb → shared_example_group_spec.rb} +31 -31
- data/spec/rspec/core/world_spec.rb +64 -83
- data/spec/spec_helper.rb +19 -30
- metadata +17 -17
- data/features-pending/command_line/line_number_option.feature +0 -56
- data/features-pending/command_line/line_number_option_with_example_with_no_name.feature +0 -22
- data/lib/rspec/core/extensions/instance_exec.rb +0 -31
- data/spec/resources/example_classes.rb +0 -67
- data/spec/rspec/core/resources/example_classes.rb +0 -67
data/.document
CHANGED
data/.gitignore
CHANGED
data/README.markdown
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# RSpec Core
|
2
2
|
|
3
|
-
|
3
|
+
rspec-core includes the runner, output formatters, and the `rspec` command.
|
4
4
|
|
5
|
-
|
5
|
+
rspec-core is currently in alpha release. While you are welcome to track, fork,
|
6
|
+
explore, etc, we're too early in the process to start fielding pull requests
|
7
|
+
and or issues from outside the core development team, so please don't waste
|
8
|
+
your time until this notice changes.
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
## Install
|
11
|
+
|
12
|
+
[sudo] gem install rspec --prerelease
|
13
|
+
|
14
|
+
This will install rspec, rspec-core, rspec-expectations and rspec-mocks.
|
9
15
|
|
10
16
|
## Known Issues
|
11
17
|
|
@@ -38,3 +44,11 @@ You can, of course, fully qualify the declaration and everything works fine:
|
|
38
44
|
Foo.new
|
39
45
|
end
|
40
46
|
end
|
47
|
+
|
48
|
+
#### Also see
|
49
|
+
|
50
|
+
* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
|
51
|
+
* [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
|
52
|
+
* [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
|
53
|
+
* [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)
|
54
|
+
|
data/Rakefile
CHANGED
@@ -15,16 +15,15 @@ begin
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
gem.name = "rspec-core"
|
17
17
|
gem.version = Rspec::Core::Version::STRING
|
18
|
-
gem.
|
19
|
-
gem.
|
18
|
+
gem.summary = Rspec::Core::Version::SUMMARY
|
19
|
+
gem.description = 'Rspec runner and example group classes'
|
20
20
|
gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
|
21
21
|
gem.homepage = "http://github.com/rspec/core"
|
22
22
|
gem.authors = ["David Chelimsky", "Chad Humphries"]
|
23
|
-
gem.
|
23
|
+
gem.rubyforge_project = "rspec"
|
24
24
|
gem.add_development_dependency "rspec-expectations", ">= #{Rspec::Core::Version::STRING}"
|
25
25
|
gem.add_development_dependency "rspec-mocks", ">= #{Rspec::Core::Version::STRING}"
|
26
26
|
gem.add_development_dependency('cucumber', '>= 0.5.3')
|
27
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
28
27
|
end
|
29
28
|
Jeweler::GemcutterTasks.new
|
30
29
|
rescue LoadError
|
@@ -32,16 +31,13 @@ rescue LoadError
|
|
32
31
|
end
|
33
32
|
|
34
33
|
begin
|
35
|
-
Rspec::Core::RakeTask.new :spec
|
36
|
-
t.pattern = "spec/**/*_spec.rb"
|
37
|
-
end
|
34
|
+
Rspec::Core::RakeTask.new :spec
|
38
35
|
|
39
36
|
desc "Run all examples using rcov"
|
40
37
|
Rspec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
|
41
38
|
t.rcov = true
|
42
39
|
t.rcov_opts = %[-Ilib -Ispec --exclude "mocks,expectations,gems/*,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*"]
|
43
40
|
t.rcov_opts << %[--no-html --aggregate coverage.data]
|
44
|
-
t.pattern = "spec/**/*_spec.rb"
|
45
41
|
end
|
46
42
|
rescue LoadError
|
47
43
|
puts "Rspec core or one of its dependencies is not installed. Install it with: gem install rspec-meta"
|
@@ -57,7 +53,7 @@ task :clobber do
|
|
57
53
|
rm_rf 'coverage'
|
58
54
|
end
|
59
55
|
|
60
|
-
if RUBY_VERSION
|
56
|
+
if RUBY_VERSION.to_f >= 1.9
|
61
57
|
Cucumber::Rake::Task.new :features do |t|
|
62
58
|
t.cucumber_opts = %w{--format progress}
|
63
59
|
end
|
@@ -76,15 +72,8 @@ end
|
|
76
72
|
|
77
73
|
|
78
74
|
Rake::RDocTask.new do |rdoc|
|
79
|
-
if File.exist?('VERSION.yml')
|
80
|
-
config = YAML.load(File.read('VERSION.yml'))
|
81
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
82
|
-
else
|
83
|
-
version = ""
|
84
|
-
end
|
85
|
-
|
86
75
|
rdoc.rdoc_dir = 'rdoc'
|
87
|
-
rdoc.title = "rspec-core #{
|
76
|
+
rdoc.title = "rspec-core #{Rspec::Core::Version::STRING}"
|
88
77
|
rdoc.rdoc_files.include('README*')
|
89
78
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
90
79
|
end
|
data/bin/rspec
CHANGED
@@ -1,10 +1,2 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
3
|
-
$LOAD_PATH.unshift(File.expand_path('../../../rspec-expectations/lib', __FILE__))
|
4
|
-
$LOAD_PATH.unshift(File.expand_path('../../../rspec-mocks/lib', __FILE__))
|
5
|
-
require 'rspec/expectations'
|
6
|
-
require 'rspec/mocks'
|
7
2
|
require 'rspec/autorun'
|
8
|
-
|
9
|
-
# TODO - this feels odd here - move to runner?
|
10
|
-
Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
|
@@ -1,3 +1,8 @@
|
|
1
|
-
lib_path = File.expand_path(
|
1
|
+
lib_path = File.expand_path('../../../lib', __FILE__)
|
2
2
|
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
3
|
-
require '
|
3
|
+
require 'rspec/autorun'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
|
6
|
+
Rspec::Core.configure do |c|
|
7
|
+
c.include Rspec::Matchers
|
8
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
Feature: example name option
|
2
|
+
|
3
|
+
Use the --example (or -e) option to filter the examples to be run by name.
|
4
|
+
|
5
|
+
The submitted argument is compiled to a Ruby Regexp, and matched against the
|
6
|
+
full description of the example, which is the concatenation of descriptions
|
7
|
+
of the group (including any nested groups) and the example.
|
8
|
+
|
9
|
+
This allows you to run a single uniquely named example, all examples with
|
10
|
+
similar names, all the example in a uniquely named group, etc, etc.
|
11
|
+
|
12
|
+
Background:
|
13
|
+
Given a file named "first_spec.rb" with:
|
14
|
+
"""
|
15
|
+
describe "first group" do
|
16
|
+
it "first example in first group" do; end
|
17
|
+
it "second example in first group" do; end
|
18
|
+
end
|
19
|
+
"""
|
20
|
+
Given a file named "second_spec.rb" with:
|
21
|
+
"""
|
22
|
+
describe "second group" do
|
23
|
+
it "first example in second group" do; end
|
24
|
+
it "second example in second group" do; end
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
|
28
|
+
Scenario: no matches
|
29
|
+
When I run "spec . --example nothing_like_this"
|
30
|
+
Then the stdout should match "0 examples, 0 failures"
|
31
|
+
|
32
|
+
Scenario: all matches
|
33
|
+
When I run "spec . --example example"
|
34
|
+
Then the stdout should match "4 examples, 0 failures"
|
35
|
+
|
36
|
+
Scenario: one match in each file
|
37
|
+
When I run "spec . --example 'first example'"
|
38
|
+
Then the stdout should match "2 examples, 0 failures"
|
39
|
+
|
40
|
+
Scenario: one match in one file
|
41
|
+
When I run "spec . --example 'first example in first group'"
|
42
|
+
Then the stdout should match "1 example, 0 failures"
|
43
|
+
|
44
|
+
Scenario: one match in one file using regexp
|
45
|
+
When I run "spec . --example 'first .* first example'"
|
46
|
+
Then the stdout should match "1 example, 0 failures"
|
47
|
+
|
48
|
+
Scenario: all examples in one group
|
49
|
+
When I run "spec . --example 'first group'"
|
50
|
+
Then the stdout should match "2 examples, 0 failures"
|
51
|
+
|
52
|
+
Scenario: one match in one file with group name
|
53
|
+
When I run "spec . --example 'second group first example'"
|
54
|
+
Then the stdout should match "1 example, 0 failures"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: line number appended to file path
|
2
|
+
|
3
|
+
As an RSpec user
|
4
|
+
I want to run one example identified by the
|
5
|
+
line number appended to the filepath
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given a file named "example_spec.rb" with:
|
9
|
+
"""
|
10
|
+
describe "a group" do
|
11
|
+
|
12
|
+
it "has a first example" do
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a second example" do
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
"""
|
22
|
+
|
23
|
+
Scenario: two examples - both examples from the group declaration
|
24
|
+
When I run "spec example_spec.rb:1 --format doc"
|
25
|
+
Then the stdout should match "2 examples, 0 failures"
|
26
|
+
And the stdout should match "has a second example"
|
27
|
+
And the stdout should match "has a first example"
|
28
|
+
|
29
|
+
Scenario: two examples - first example on declaration line
|
30
|
+
When I run "spec example_spec.rb:3 --format doc"
|
31
|
+
Then the stdout should match "1 example, 0 failures"
|
32
|
+
And the stdout should match "has a first example"
|
33
|
+
But the stdout should not match "has a second example"
|
34
|
+
|
35
|
+
Scenario: two examples - second example on declaration line
|
36
|
+
When I run "spec example_spec.rb:7 --format doc"
|
37
|
+
Then the stdout should match "1 example, 0 failures"
|
38
|
+
And the stdout should match "has a second example"
|
39
|
+
But the stdout should not match "has a first example"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: line number option
|
2
|
+
|
3
|
+
As an Rspec user
|
4
|
+
I want to run one example identified by the line number
|
5
|
+
|
6
|
+
Scenario: standard examples
|
7
|
+
Given a file named "example_spec.rb" with:
|
8
|
+
"""
|
9
|
+
describe 9 do
|
10
|
+
|
11
|
+
it "should be > 8" do
|
12
|
+
9.should be > 8
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be < 10" do
|
16
|
+
9.should be < 10
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
"""
|
21
|
+
When I run "spec example_spec.rb --line 3 --format doc"
|
22
|
+
Then the stdout should match "1 example, 0 failures"
|
23
|
+
Then the stdout should match "should be > 8"
|
24
|
+
But the stdout should not match "should be < 10"
|
25
|
+
|
26
|
+
Scenario: one liner
|
27
|
+
Given a file named "example_spec.rb" with:
|
28
|
+
"""
|
29
|
+
describe 9 do
|
30
|
+
|
31
|
+
it { should be > 8 }
|
32
|
+
|
33
|
+
it { should be < 10 }
|
34
|
+
|
35
|
+
end
|
36
|
+
"""
|
37
|
+
When I run "spec example_spec.rb --line 3 --format doc"
|
38
|
+
Then the stdout should match "1 example, 0 failures"
|
39
|
+
Then the stdout should match "should be > 8"
|
40
|
+
But the stdout should not match "should be < 10"
|
@@ -7,6 +7,8 @@ Feature: define matcher
|
|
7
7
|
Scenario: define a matcher with default messages
|
8
8
|
Given a file named "matcher_with_default_message_spec.rb" with:
|
9
9
|
"""
|
10
|
+
require 'rspec/expectations'
|
11
|
+
|
10
12
|
Rspec::Matchers.define :be_a_multiple_of do |expected|
|
11
13
|
match do |actual|
|
12
14
|
actual % expected == 0
|
@@ -37,8 +39,8 @@ Feature: define matcher
|
|
37
39
|
|
38
40
|
And the stdout should match "should be a multiple of 3"
|
39
41
|
And the stdout should match "should not be a multiple of 4"
|
40
|
-
And the stdout should match "
|
41
|
-
And the stdout should match "
|
42
|
+
And the stdout should match "Failure/Error: it {should be_a_multiple_of(4)}"
|
43
|
+
And the stdout should match "Failure/Error: it {should_not be_a_multiple_of(3)}"
|
42
44
|
|
43
45
|
And the stdout should match "4 examples, 2 failures"
|
44
46
|
And the stdout should match "expected 9 to be a multiple of 4"
|
@@ -47,6 +49,8 @@ Feature: define matcher
|
|
47
49
|
Scenario: overriding the failure_message_for_should
|
48
50
|
Given a file named "matcher_with_failure_message_spec.rb" with:
|
49
51
|
"""
|
52
|
+
require 'rspec/expectations'
|
53
|
+
|
50
54
|
Rspec::Matchers.define :be_a_multiple_of do |expected|
|
51
55
|
match do |actual|
|
52
56
|
actual % expected == 0
|
@@ -69,6 +73,8 @@ Feature: define matcher
|
|
69
73
|
Scenario: overriding the failure_message_for_should_not
|
70
74
|
Given a file named "matcher_with_failure_for_message_spec.rb" with:
|
71
75
|
"""
|
76
|
+
require 'rspec/expectations'
|
77
|
+
|
72
78
|
Rspec::Matchers.define :be_a_multiple_of do |expected|
|
73
79
|
match do |actual|
|
74
80
|
actual % expected == 0
|
@@ -91,6 +97,8 @@ Feature: define matcher
|
|
91
97
|
Scenario: overriding the description
|
92
98
|
Given a file named "matcher_overriding_description_spec.rb" with:
|
93
99
|
"""
|
100
|
+
require 'rspec/expectations'
|
101
|
+
|
94
102
|
Rspec::Matchers.define :be_a_multiple_of do |expected|
|
95
103
|
match do |actual|
|
96
104
|
actual % expected == 0
|
@@ -117,6 +125,8 @@ Feature: define matcher
|
|
117
125
|
Scenario: with no args
|
118
126
|
Given a file named "matcher_with_no_args_spec.rb" with:
|
119
127
|
"""
|
128
|
+
require 'rspec/expectations'
|
129
|
+
|
120
130
|
Rspec::Matchers.define :have_7_fingers do
|
121
131
|
match do |thing|
|
122
132
|
thing.fingers.length == 7
|
@@ -139,6 +149,8 @@ Feature: define matcher
|
|
139
149
|
Scenario: with multiple args
|
140
150
|
Given a file named "matcher_with_multiple_args_spec.rb" with:
|
141
151
|
"""
|
152
|
+
require 'rspec/expectations'
|
153
|
+
|
142
154
|
Rspec::Matchers.define :be_the_sum_of do |a,b,c,d|
|
143
155
|
match do |sum|
|
144
156
|
a + b + c + d == sum
|
@@ -157,16 +169,18 @@ Feature: define matcher
|
|
157
169
|
Scenario: with helper methods
|
158
170
|
Given a file named "matcher_with_internal_helper_spec.rb" with:
|
159
171
|
"""
|
172
|
+
require 'rspec/expectations'
|
173
|
+
|
160
174
|
Rspec::Matchers.define :have_same_elements_as do |sample|
|
161
175
|
match do |actual|
|
162
176
|
similar?(sample, actual)
|
163
177
|
end
|
164
|
-
|
178
|
+
|
165
179
|
def similar?(a, b)
|
166
180
|
a.sort == b.sort
|
167
181
|
end
|
168
182
|
end
|
169
|
-
|
183
|
+
|
170
184
|
describe "these two arrays" do
|
171
185
|
specify "should be similar" do
|
172
186
|
[1,2,3].should have_same_elements_as([2,3,1])
|
@@ -7,7 +7,6 @@ Feature: define matcher outside rspec
|
|
7
7
|
Scenario: define a matcher with default messages
|
8
8
|
Given a file named "test_multiples.rb" with:
|
9
9
|
"""
|
10
|
-
$:.unshift File.join(File.dirname(__FILE__), "/../../lib")
|
11
10
|
require 'test/unit'
|
12
11
|
require 'rspec/expectations'
|
13
12
|
|
@@ -36,4 +35,4 @@ Feature: define matcher outside rspec
|
|
36
35
|
When I run "ruby test_multiples.rb"
|
37
36
|
Then the exit code should be 256
|
38
37
|
And the stdout should match "expected 9 to be a multiple of 4"
|
39
|
-
And the stdout should match "2 tests, 0 assertions,
|
38
|
+
And the stdout should match "2 tests, 0 assertions, 0 failures, 1 errors"
|
@@ -5,6 +5,8 @@ Feature: explicit subject
|
|
5
5
|
Scenario: subject in top level group
|
6
6
|
Given a file named "top_level_subject_spec.rb" with:
|
7
7
|
"""
|
8
|
+
require 'rspec/expectations'
|
9
|
+
|
8
10
|
describe Array, "with some elements" do
|
9
11
|
subject { [1,2,3] }
|
10
12
|
it "should have the prescribed elements" do
|
@@ -18,6 +20,8 @@ Feature: explicit subject
|
|
18
20
|
Scenario: subject in a nested group
|
19
21
|
Given a file named "nested_subject_spec.rb" with:
|
20
22
|
"""
|
23
|
+
require 'rspec/expectations'
|
24
|
+
|
21
25
|
describe Array do
|
22
26
|
subject { [1,2,3] }
|
23
27
|
describe "with some elements" do
|
@@ -7,6 +7,8 @@ Feature: implicit subject
|
|
7
7
|
Scenario: subject in top level group
|
8
8
|
Given a file named "top_level_subject_spec.rb" with:
|
9
9
|
"""
|
10
|
+
require 'rspec/expectations'
|
11
|
+
|
10
12
|
describe Array, "when first created" do
|
11
13
|
it "should be empty" do
|
12
14
|
subject.should == []
|
@@ -19,6 +21,8 @@ Feature: implicit subject
|
|
19
21
|
Scenario: subject in a nested group
|
20
22
|
Given a file named "nested_subject_spec.rb" with:
|
21
23
|
"""
|
24
|
+
require 'rspec/expectations'
|
25
|
+
|
22
26
|
describe Array do
|
23
27
|
describe "when first created" do
|
24
28
|
it "should be empty" do
|
data/features/support/env.rb
CHANGED
@@ -51,10 +51,24 @@ class RspecWorld
|
|
51
51
|
def ruby(args)
|
52
52
|
stderr_file = Tempfile.new('rspec')
|
53
53
|
stderr_file.close
|
54
|
+
|
54
55
|
Dir.chdir(working_dir) do
|
55
|
-
|
56
|
+
File.open('load_paths.rb', 'w') do |f|
|
57
|
+
f.write <<-CONTENT
|
58
|
+
$LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
|
59
|
+
$LOAD_PATH.unshift(File.expand_path('../../../../rspec-expectations/lib', __FILE__))
|
60
|
+
$LOAD_PATH.unshift(File.expand_path('../../../../rspec-mocks/lib', __FILE__))
|
61
|
+
require 'rspec/core'
|
62
|
+
require 'rspec/expectations'
|
63
|
+
Rspec::Core::ExampleGroup.__send__(:include, Rspec::Matchers)
|
64
|
+
CONTENT
|
65
|
+
end
|
66
|
+
cmd = "-rrubygems -rload_paths.rb #{rspec_libs} #{args}"
|
67
|
+
# p cmd
|
68
|
+
@stdout = super(cmd, stderr_file.path)
|
56
69
|
end
|
57
70
|
@stderr = IO.read(stderr_file.path)
|
71
|
+
p @stderr unless @stderr == ""
|
58
72
|
@exit_code = $?.to_i
|
59
73
|
end
|
60
74
|
|