rspec-core 2.0.0.beta.3 → 2.0.0.beta.4
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/Rakefile +1 -0
- data/VERSION +1 -1
- data/autotest/discover.rb +2 -0
- data/features/configuration/spec_opts.feature +3 -3
- data/{features-pending → features}/formatters/custom_formatter.feature +4 -4
- data/features/pending/pending_examples.feature +68 -0
- data/lib/autotest/rspec2.rb +54 -0
- data/lib/rspec/core.rb +7 -2
- data/lib/rspec/core/example_group.rb +7 -3
- data/lib/rspec/core/formatters/base_formatter.rb +3 -3
- data/lib/rspec/core/mocking/with_rr.rb +1 -1
- data/lib/rspec/core/runner.rb +1 -1
- data/lib/rspec/core/world.rb +5 -5
- data/rspec-core.gemspec +25 -20
- data/spec/autotest/failed_results_re_spec.rb +31 -0
- data/spec/autotest/rspec_spec.rb +130 -0
- data/spec/rspec/core/formatters/base_formatter_spec.rb +19 -79
- data/spec/rspec/core/runner_spec.rb +1 -1
- data/spec/rspec/core/shared_example_group_spec.rb +56 -14
- data/spec/rspec/core_spec.rb +8 -4
- data/spec/spec_helper.rb +13 -3
- data/spec/support/matchers.rb +44 -0
- data/specs.watchr +5 -3
- metadata +33 -17
- data/features-pending/heckle/heckle.feature +0 -56
- data/features-pending/interop/examples_and_tests_together.feature +0 -80
- data/features-pending/interop/rspec_output.feature +0 -25
- data/features-pending/interop/test_but_not_test_unit.feature +0 -26
- data/features-pending/interop/test_case_with_should_methods.feature +0 -46
- data/features-pending/mocks/stub_implementation.feature +0 -26
- data/features-pending/pending/pending_examples.feature +0 -81
@@ -0,0 +1,130 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Autotest::Rspec do
|
4
|
+
describe "adding spec.opts --options" do
|
5
|
+
before(:each) do
|
6
|
+
@rspec_autotest = Autotest::Rspec2.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return the command line option to add spec.opts if the options file exists" do
|
10
|
+
File.stub!(:exist?).and_return true
|
11
|
+
@rspec_autotest.add_options_if_present.should == "-O spec/spec.opts "
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return an empty string if no spec.opts exists" do
|
15
|
+
File.stub!(:exist?).and_return false
|
16
|
+
Autotest::Rspec2.new.add_options_if_present.should == ""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "commands" do
|
21
|
+
before(:each) do
|
22
|
+
@rspec_autotest = Autotest::Rspec2.new
|
23
|
+
@rspec_autotest.stub!(:ruby).and_return "ruby"
|
24
|
+
@rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
|
25
|
+
|
26
|
+
@ruby = @rspec_autotest.ruby
|
27
|
+
@spec_cmd = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec'))
|
28
|
+
@options = @rspec_autotest.add_options_if_present
|
29
|
+
files = %w[file_one file_two]
|
30
|
+
@files_to_test = {
|
31
|
+
files[0] => [],
|
32
|
+
files[1] => []
|
33
|
+
}
|
34
|
+
# this is not the inner representation of Autotest!
|
35
|
+
@rspec_autotest.files_to_test = @files_to_test
|
36
|
+
@to_test = files.map { |f| File.expand_path(f) }.join ' '
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should make the appropriate test command" do
|
40
|
+
actual = @rspec_autotest.make_test_cmd(@files_to_test)
|
41
|
+
expected = /#{@ruby} #{@spec_cmd} (.*) #{@options}/
|
42
|
+
|
43
|
+
actual.should match(expected)
|
44
|
+
|
45
|
+
actual =~ expected
|
46
|
+
$1.should =~ /#{File.expand_path('file_one')}/
|
47
|
+
$1.should =~ /#{File.expand_path('file_two')}/
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return a blank command for no files" do
|
51
|
+
@rspec_autotest.make_test_cmd({}).should == ''
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "mappings" do
|
56
|
+
|
57
|
+
before(:each) do
|
58
|
+
@lib_file = "lib/something.rb"
|
59
|
+
@spec_file = "spec/something_spec.rb"
|
60
|
+
@rspec_autotest = Autotest::Rspec2.new
|
61
|
+
@rspec_autotest.hook :initialize
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should find the spec file for a given lib file" do
|
65
|
+
@rspec_autotest.should map_specs([@spec_file]).to(@lib_file)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should find the spec file if given a spec file" do
|
69
|
+
@rspec_autotest.should map_specs([@spec_file]).to(@spec_file)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should ignore files in spec dir that aren't specs" do
|
73
|
+
@rspec_autotest.should map_specs([]).to("spec/spec_helper.rb")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should ignore untracked files (in @file)" do
|
77
|
+
@rspec_autotest.should map_specs([]).to("lib/untracked_file")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "consolidating failures" do
|
82
|
+
before(:each) do
|
83
|
+
@rspec_autotest = Autotest::Rspec2.new
|
84
|
+
|
85
|
+
@spec_file = "spec/autotest/some_spec.rb"
|
86
|
+
@rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
|
87
|
+
@rspec_autotest.stub!(:find_files_to_test).and_return true
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return no failures if no failures were given in the output" do
|
91
|
+
@rspec_autotest.consolidate_failures([[]]).should == {}
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return a hash with the spec filename => spec name for each failure or error" do
|
95
|
+
@rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb"
|
96
|
+
failures = [
|
97
|
+
[
|
98
|
+
"false should be false",
|
99
|
+
"expected: true,\n got: false (using ==)\n#{@spec_file}:203:"
|
100
|
+
]
|
101
|
+
]
|
102
|
+
@rspec_autotest.consolidate_failures(failures).should == {
|
103
|
+
@spec_file => ["false should be false"]
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not include the subject file" do
|
108
|
+
subject_file = "lib/autotest/some.rb"
|
109
|
+
@rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb"
|
110
|
+
failures = [
|
111
|
+
[
|
112
|
+
"false should be false",
|
113
|
+
"expected: true,\n got: false (using ==)\n#{subject_file}:143:\n#{@spec_file}:203:"
|
114
|
+
]
|
115
|
+
]
|
116
|
+
@rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "normalizing file names" do
|
121
|
+
it "should ensure that a single file appears in files_to_test only once" do
|
122
|
+
@rspec_autotest = Autotest::Rspec2.new
|
123
|
+
@files_to_test = {}
|
124
|
+
['filename.rb', './filename.rb', File.expand_path('filename.rb')].each do |file|
|
125
|
+
@files_to_test[file] = []
|
126
|
+
end
|
127
|
+
@rspec_autotest.normalize(@files_to_test).should have(1).file
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -1,104 +1,44 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Rspec::Core::Formatters::BaseFormatter do
|
4
4
|
|
5
|
-
|
6
|
-
@formatter = Rspec::Core::Formatters::BaseFormatter.new
|
7
|
-
end
|
8
|
-
|
9
|
-
class HaveInterfaceMatcher
|
10
|
-
def initialize(method)
|
11
|
-
@method = method
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :object
|
15
|
-
attr_reader :method
|
16
|
-
|
17
|
-
def matches?(object)
|
18
|
-
@object = object
|
19
|
-
object.respond_to?(@method)
|
20
|
-
end
|
21
|
-
|
22
|
-
def with(arity)
|
23
|
-
WithArity.new(self, @method, arity)
|
24
|
-
end
|
25
|
-
|
26
|
-
class WithArity
|
27
|
-
def initialize(matcher, method, arity)
|
28
|
-
@have_matcher = matcher
|
29
|
-
@method = method
|
30
|
-
@arity = arity
|
31
|
-
end
|
32
|
-
|
33
|
-
def matches?(an_object)
|
34
|
-
@have_matcher.matches?(an_object) && real_arity == @arity
|
35
|
-
end
|
36
|
-
|
37
|
-
def failure_message
|
38
|
-
"#{@have_matcher} should have method :#{@method} with #{argument_arity}, but it had #{real_arity}"
|
39
|
-
end
|
40
|
-
|
41
|
-
def arguments
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
alias_method :argument, :arguments
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def real_arity
|
50
|
-
@have_matcher.object.method(@method).arity
|
51
|
-
end
|
52
|
-
|
53
|
-
def argument_arity
|
54
|
-
if @arity == 1
|
55
|
-
"1 argument"
|
56
|
-
else
|
57
|
-
"#{@arity} arguments"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def have_interface_for(method)
|
64
|
-
HaveInterfaceMatcher.new(method)
|
65
|
-
end
|
5
|
+
let(:formatter) { Rspec::Core::Formatters::BaseFormatter.new }
|
66
6
|
|
67
|
-
it "
|
68
|
-
|
7
|
+
it "has start as an interface with one argument" do
|
8
|
+
formatter.should have_interface_for(:start).with(1).argument
|
69
9
|
end
|
70
10
|
|
71
|
-
it "
|
72
|
-
|
11
|
+
it "has add_example_group as an interface with one argument" do
|
12
|
+
formatter.should have_interface_for(:add_example_group).with(1).argument
|
73
13
|
end
|
74
14
|
|
75
|
-
it "
|
76
|
-
|
15
|
+
it "has example_finished as an interface with one argument" do
|
16
|
+
formatter.should have_interface_for(:example_finished).with(1).arguments
|
77
17
|
end
|
78
18
|
|
79
|
-
it "
|
80
|
-
|
19
|
+
it "has start_dump as an interface with 1 arguments" do
|
20
|
+
formatter.should have_interface_for(:start_dump).with(1).arguments
|
81
21
|
end
|
82
22
|
|
83
|
-
it "
|
84
|
-
|
23
|
+
it "has dump_failures as an interface with no arguments" do
|
24
|
+
formatter.should have_interface_for(:dump_failures).with(0).arguments
|
85
25
|
end
|
86
26
|
|
87
|
-
it "
|
88
|
-
|
27
|
+
it "has dump_summary as an interface with zero arguments" do
|
28
|
+
formatter.should have_interface_for(:dump_summary).with(0).arguments
|
89
29
|
end
|
90
30
|
|
91
|
-
it "
|
92
|
-
|
31
|
+
it "has dump_pending as an interface with zero arguments" do
|
32
|
+
formatter.should have_interface_for(:dump_pending).with(0).arguments
|
93
33
|
end
|
94
34
|
|
95
|
-
it "
|
96
|
-
|
35
|
+
it "has close as an interface with zero arguments" do
|
36
|
+
formatter.should have_interface_for(:close).with(0).arguments
|
97
37
|
end
|
98
38
|
|
99
39
|
describe '#format_backtrace' do
|
100
40
|
|
101
|
-
it "
|
41
|
+
it "displays the full backtrace when the example is given the :full_backtrace => true option", :full_backtrace => true
|
102
42
|
|
103
43
|
end
|
104
44
|
|
@@ -5,7 +5,7 @@ describe Rspec::Core::Runner do
|
|
5
5
|
describe 'reporter' do
|
6
6
|
|
7
7
|
it 'should return the configured formatter' do
|
8
|
-
Rspec::Core::Runner.new.reporter.should == Rspec
|
8
|
+
Rspec::Core::Runner.new.reporter.should == Rspec.configuration.formatter
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
@@ -65,7 +65,14 @@ module Rspec::Core
|
|
65
65
|
group.singleton_methods.should include(:class_helper)
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
68
|
+
it "raises when named shared example_group can not be found" do
|
69
|
+
cleanup_shared_example_groups do
|
70
|
+
group = ExampleGroup.create("example_group")
|
71
|
+
lambda do
|
72
|
+
group.it_should_behave_like("a group that does not exist")
|
73
|
+
end.should raise_error(/Could not find shared example group named/)
|
74
|
+
end
|
75
|
+
end
|
69
76
|
|
70
77
|
it "adds examples to current example_group using it_should_behave_like" do
|
71
78
|
cleanup_shared_example_groups do
|
@@ -142,35 +149,70 @@ module Rspec::Core
|
|
142
149
|
share_examples_for("it runs shared examples") do
|
143
150
|
include RunningSharedExamplesJustForTesting
|
144
151
|
|
152
|
+
class << self
|
153
|
+
def magic
|
154
|
+
$magic ||= {}
|
155
|
+
end
|
156
|
+
|
157
|
+
def count(scope)
|
158
|
+
@counters ||= {
|
159
|
+
:before_all => 0,
|
160
|
+
:before_each => 0,
|
161
|
+
:after_each => 0,
|
162
|
+
:after_all => 0
|
163
|
+
}
|
164
|
+
@counters[scope] += 1
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
145
168
|
def magic
|
146
|
-
|
169
|
+
$magic ||= {}
|
170
|
+
end
|
171
|
+
|
172
|
+
def count(scope)
|
173
|
+
self.class.count(scope)
|
147
174
|
end
|
148
175
|
|
149
|
-
before(:
|
150
|
-
|
151
|
-
|
176
|
+
before(:all) { magic[:before_all] = "before all #{count(:before_all)}" }
|
177
|
+
before(:each) { magic[:before_each] = "before each #{count(:before_each)}" }
|
178
|
+
after(:each) { magic[:after_each] = "after each #{count(:after_each)}" }
|
179
|
+
after(:all) { magic[:after_all] = "after all #{count(:after_all)}" }
|
152
180
|
end
|
153
181
|
|
154
|
-
|
182
|
+
let(:group) do
|
183
|
+
group = ExampleGroup.create("example group") do
|
184
|
+
it_should_behave_like "it runs shared examples"
|
185
|
+
it "has one example" do; end
|
186
|
+
it "has another example" do; end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
before { group.run(stub('reporter').as_null_object) }
|
191
|
+
|
192
|
+
it "runs before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
|
193
|
+
group.magic[:before_all].should eq("before all 1")
|
194
|
+
end
|
155
195
|
|
156
196
|
it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
|
157
|
-
magic[:before_each].should
|
197
|
+
group.magic[:before_each].should eq("before each 2")
|
158
198
|
end
|
159
199
|
|
160
|
-
it "runs after(:each) from shared example_group", :compat => 'rspec-1.2'
|
200
|
+
it "runs after(:each) from shared example_group", :compat => 'rspec-1.2' do
|
201
|
+
group.magic[:after_each].should eq("after each 2")
|
202
|
+
end
|
161
203
|
|
162
|
-
it "
|
163
|
-
magic[:
|
204
|
+
it "runs after(:all) only once from shared example_group", :compat => 'rspec-1.2' do
|
205
|
+
group.magic[:after_all].should eq("after all 1")
|
164
206
|
end
|
165
207
|
|
166
|
-
|
208
|
+
it_should_behave_like "it runs shared examples"
|
167
209
|
|
168
|
-
it "
|
210
|
+
it "includes modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
|
169
211
|
running_example.example_group.included_modules.should include(RunningSharedExamplesJustForTesting)
|
170
212
|
end
|
171
213
|
|
172
|
-
it "
|
173
|
-
magic.should be_a(Hash)
|
214
|
+
it "makes methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
|
215
|
+
group.magic.should be_a(Hash)
|
174
216
|
end
|
175
217
|
|
176
218
|
end
|
data/spec/rspec/core_spec.rb
CHANGED
@@ -4,17 +4,21 @@ describe Rspec::Core do
|
|
4
4
|
|
5
5
|
describe "#configuration" do
|
6
6
|
|
7
|
-
it "
|
8
|
-
Rspec
|
7
|
+
it "returns an instance of Rspec::Core::Configuration" do
|
8
|
+
Rspec.configuration.should be_an_instance_of(Rspec::Core::Configuration)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
it "returns the same object every time" do
|
12
|
+
Rspec.configuration.should equal(Rspec.configuration)
|
13
|
+
end
|
14
|
+
|
11
15
|
end
|
12
16
|
|
13
17
|
describe "#configure" do
|
14
18
|
|
15
19
|
it "should yield the current configuration" do
|
16
20
|
Rspec.configure do |config|
|
17
|
-
config.should == Rspec::
|
21
|
+
config.should == Rspec::configuration
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
data/spec/spec_helper.rb
CHANGED
@@ -6,8 +6,18 @@ $LOAD_PATH << File.expand_path('../../../rspec-mocks/lib', __FILE__)
|
|
6
6
|
require 'rspec/expectations'
|
7
7
|
require 'rspec/mocks'
|
8
8
|
|
9
|
+
begin
|
10
|
+
require 'autotest'
|
11
|
+
rescue LoadError
|
12
|
+
raise "You must install ZenTest to use autotest"
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'autotest/rspec2'
|
16
|
+
|
9
17
|
Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
|
10
18
|
|
19
|
+
Dir['./spec/support/**/*.rb'].map {|f| require f}
|
20
|
+
|
11
21
|
module Rspec
|
12
22
|
module Core
|
13
23
|
module Matchers
|
@@ -23,11 +33,11 @@ module Rspec
|
|
23
33
|
end
|
24
34
|
|
25
35
|
def use_formatter(new_formatter)
|
26
|
-
original_formatter = Rspec
|
27
|
-
Rspec
|
36
|
+
original_formatter = Rspec.configuration.formatter
|
37
|
+
Rspec.configuration.instance_variable_set(:@formatter, new_formatter)
|
28
38
|
yield
|
29
39
|
ensure
|
30
|
-
Rspec
|
40
|
+
Rspec.configuration.instance_variable_set(:@formatter, original_formatter)
|
31
41
|
end
|
32
42
|
|
33
43
|
def in_editor?
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Rspec::Matchers.define :map_specs do |specs|
|
2
|
+
match do |autotest|
|
3
|
+
@specs = specs
|
4
|
+
@autotest = prepare(autotest)
|
5
|
+
autotest.test_files_for(@file) == specs
|
6
|
+
end
|
7
|
+
|
8
|
+
chain :to do |file|
|
9
|
+
@file = file
|
10
|
+
end
|
11
|
+
|
12
|
+
failure_message_for_should do
|
13
|
+
"expected #{@autotest.class} to map #{@specs.inspect} to #{@file.inspect}\ngot #{@actual.inspect}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare(autotest)
|
17
|
+
find_order = @specs.dup << @file
|
18
|
+
autotest.instance_eval { @find_order = find_order }
|
19
|
+
autotest
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Rspec::Matchers.define :have_interface_for do |method|
|
24
|
+
match do |object|
|
25
|
+
@method = method
|
26
|
+
@object = object
|
27
|
+
object.respond_to?(method) && actual_arity == @expected_arity
|
28
|
+
end
|
29
|
+
|
30
|
+
chain :with do |arity|
|
31
|
+
@expected_arity = arity
|
32
|
+
end
|
33
|
+
|
34
|
+
chain(:argument) {}
|
35
|
+
chain(:arguments) {}
|
36
|
+
|
37
|
+
failure_message_for_should do
|
38
|
+
"#{@object} should have method :#{@method} with #{@expected_arity} argument(s), but it had #{actual_arity}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def actual_arity
|
42
|
+
@object.method(@method).arity
|
43
|
+
end
|
44
|
+
end
|