rspec-core 2.0.0.beta.22 → 2.6.0
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/.gitignore +1 -0
- data/.rspec +0 -1
- data/.travis.yml +7 -0
- data/Gemfile +46 -20
- data/Guardfile +5 -0
- data/License.txt +2 -1
- data/{README.markdown → README.md} +23 -5
- data/Rakefile +58 -31
- data/bin/autospec +13 -0
- data/bin/rspec +24 -2
- data/cucumber.yml +1 -1
- data/features/.nav +57 -0
- data/features/Autotest.md +38 -0
- data/features/Changelog.md +269 -0
- data/features/README.md +17 -0
- data/features/Upgrade.md +320 -0
- data/features/command_line/README.md +28 -0
- data/features/command_line/configure.feature +18 -15
- data/features/command_line/example_name_option.feature +37 -23
- data/features/command_line/exit_status.feature +16 -31
- data/features/command_line/format_option.feature +73 -0
- data/features/command_line/line_number_appended_to_path.feature +25 -27
- data/features/command_line/line_number_option.feature +11 -10
- data/features/command_line/rake_task.feature +68 -0
- data/features/command_line/tag.feature +90 -0
- data/features/configuration/alias_example_to.feature +48 -0
- data/features/configuration/custom_settings.feature +8 -10
- data/features/configuration/fail_fast.feature +77 -0
- data/features/configuration/read_options_from_file.feature +42 -26
- data/features/example_groups/basic_structure.feature +55 -0
- data/features/example_groups/shared_context.feature +74 -0
- data/features/example_groups/shared_example_group.feature +56 -41
- data/features/expectation_framework_integration/configure_expectation_framework.feature +73 -0
- data/features/filtering/exclusion_filters.feature +69 -9
- data/features/filtering/if_and_unless.feature +168 -0
- data/features/filtering/inclusion_filters.feature +58 -26
- data/features/filtering/run_all_when_everything_filtered.feature +46 -0
- data/features/formatters/custom_formatter.feature +17 -13
- data/features/formatters/text_formatter.feature +43 -0
- data/features/helper_methods/arbitrary_methods.feature +40 -0
- data/features/helper_methods/let.feature +50 -0
- data/features/helper_methods/modules.feature +149 -0
- data/features/hooks/around_hooks.feature +99 -69
- data/features/hooks/before_and_after_hooks.feature +74 -40
- data/features/hooks/filtering.feature +227 -0
- data/features/metadata/current_example.feature +17 -0
- data/features/metadata/described_class.feature +17 -0
- data/features/metadata/user_defined.feature +111 -0
- data/features/mock_framework_integration/use_any_framework.feature +106 -0
- data/features/mock_framework_integration/use_flexmock.feature +84 -11
- data/features/mock_framework_integration/use_mocha.feature +85 -11
- data/features/mock_framework_integration/use_rr.feature +86 -11
- data/features/mock_framework_integration/use_rspec.feature +85 -11
- data/features/pending/pending_examples.feature +143 -5
- data/features/spec_files/arbitrary_file_suffix.feature +2 -2
- data/features/step_definitions/additional_cli_steps.rb +30 -0
- data/features/subject/attribute_of_subject.feature +93 -15
- data/features/subject/explicit_subject.feature +28 -17
- data/features/subject/implicit_receiver.feature +29 -0
- data/features/subject/implicit_subject.feature +9 -10
- data/features/support/env.rb +6 -1
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rspec2.rb +15 -11
- data/lib/rspec/autorun.rb +2 -0
- data/lib/rspec/core/backward_compatibility.rb +33 -4
- data/lib/rspec/core/command_line.rb +4 -28
- data/lib/rspec/core/command_line_configuration.rb +16 -16
- data/lib/rspec/core/configuration.rb +279 -89
- data/lib/rspec/core/configuration_options.rb +46 -35
- data/lib/rspec/core/deprecation.rb +1 -1
- data/lib/rspec/core/drb_command_line.rb +5 -11
- data/lib/rspec/core/example.rb +63 -39
- data/lib/rspec/core/example_group.rb +109 -59
- data/lib/rspec/core/expecting/with_rspec.rb +11 -0
- data/lib/rspec/core/expecting/with_stdlib.rb +9 -0
- data/lib/rspec/core/extensions/kernel.rb +1 -1
- data/lib/rspec/core/extensions/object.rb +1 -3
- data/lib/rspec/core/formatters/base_formatter.rb +22 -11
- data/lib/rspec/core/formatters/base_text_formatter.rb +46 -30
- data/lib/rspec/core/formatters/documentation_formatter.rb +4 -2
- data/lib/rspec/core/formatters/helpers.rb +0 -4
- data/lib/rspec/core/formatters/html_formatter.rb +146 -41
- data/lib/rspec/core/formatters/progress_formatter.rb +1 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
- data/lib/rspec/core/formatters/text_mate_formatter.rb +3 -1
- data/lib/rspec/core/hooks.rb +55 -17
- data/lib/rspec/core/metadata.rb +75 -64
- data/lib/rspec/core/metadata_hash_builder.rb +93 -0
- data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
- data/lib/rspec/core/mocking/with_mocha.rb +2 -0
- data/lib/rspec/core/mocking/with_rr.rb +2 -0
- data/lib/rspec/core/mocking/with_rspec.rb +3 -1
- data/lib/rspec/core/option_parser.rb +48 -5
- data/lib/rspec/core/pending.rb +22 -4
- data/lib/rspec/core/rake_task.rb +64 -28
- data/lib/rspec/core/reporter.rb +3 -2
- data/lib/rspec/core/ruby_project.rb +2 -2
- data/lib/rspec/core/runner.rb +50 -6
- data/lib/rspec/core/shared_context.rb +16 -0
- data/lib/rspec/core/shared_example_group.rb +19 -4
- data/lib/rspec/core/subject.rb +92 -65
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +83 -25
- data/lib/rspec/core.rb +40 -24
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
- data/rspec-core.gemspec +4 -25
- data/script/FullBuildRakeFile +63 -0
- data/script/cucumber +1 -0
- data/script/full_build +1 -0
- data/script/spec +1 -0
- data/spec/autotest/discover_spec.rb +19 -0
- data/spec/autotest/failed_results_re_spec.rb +25 -9
- data/spec/autotest/rspec_spec.rb +32 -41
- data/spec/rspec/core/command_line_spec.rb +62 -7
- data/spec/rspec/core/configuration_options_spec.rb +184 -148
- data/spec/rspec/core/configuration_spec.rb +406 -108
- data/spec/rspec/core/deprecations_spec.rb +38 -1
- data/spec/rspec/core/drb_command_line_spec.rb +21 -56
- data/spec/rspec/core/example_group_spec.rb +366 -127
- data/spec/rspec/core/example_spec.rb +125 -45
- data/spec/rspec/core/formatters/base_formatter_spec.rb +61 -1
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +39 -5
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +7 -6
- data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +199 -81
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +199 -83
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +199 -81
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +206 -81
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +206 -61
- data/spec/rspec/core/formatters/html_formatter_spec.rb +17 -9
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +199 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +206 -81
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +206 -81
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +22 -7
- data/spec/rspec/core/hooks_filtering_spec.rb +128 -5
- data/spec/rspec/core/hooks_spec.rb +90 -4
- data/spec/rspec/core/metadata_spec.rb +176 -163
- data/spec/rspec/core/option_parser_spec.rb +73 -6
- data/spec/rspec/core/pending_example_spec.rb +137 -35
- data/spec/rspec/core/rake_task_spec.rb +62 -29
- data/spec/rspec/core/reporter_spec.rb +20 -4
- data/spec/rspec/core/resources/formatter_specs.rb +25 -1
- data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
- data/spec/rspec/core/runner_spec.rb +60 -10
- data/spec/rspec/core/shared_context_spec.rb +30 -0
- data/spec/rspec/core/shared_example_group_spec.rb +59 -23
- data/spec/rspec/core/subject_spec.rb +136 -0
- data/spec/rspec/core/world_spec.rb +211 -68
- data/spec/rspec/core_spec.rb +28 -0
- data/spec/spec_helper.rb +41 -23
- data/spec/support/matchers.rb +44 -13
- data/spec/support/shared_example_groups.rb +41 -0
- data/spec/support/spec_files.rb +44 -0
- data/spec.txt +1126 -0
- metadata +99 -168
- data/.treasure_map.rb +0 -23
- data/History.md +0 -30
- data/Upgrade.markdown +0 -150
- data/autotest/discover.rb +0 -2
- data/features/README.markdown +0 -12
- data/features/example_groups/describe_aliases.feature +0 -25
- data/features/example_groups/nested_groups.feature +0 -44
- data/features/hooks/described_class.feature +0 -14
- data/features/hooks/halt.feature +0 -26
- data/lib/rspec/core/around_proxy.rb +0 -14
- data/lib/rspec/core/formatters.rb +0 -8
- data/spec/ruby_forker.rb +0 -13
- data/specs.watchr +0 -59
|
@@ -6,7 +6,6 @@ module RSpec::Core
|
|
|
6
6
|
|
|
7
7
|
%w[share_examples_for shared_examples_for].each do |method_name|
|
|
8
8
|
describe method_name do
|
|
9
|
-
|
|
10
9
|
it "is exposed to the global namespace" do
|
|
11
10
|
Kernel.should respond_to(method_name)
|
|
12
11
|
end
|
|
@@ -19,32 +18,49 @@ module RSpec::Core
|
|
|
19
18
|
end.should raise_error(ArgumentError, "Shared example group 'shared group' already exists")
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
context "given a string" do
|
|
22
|
+
it "captures the given string and block in the World's collection of shared example groups" do
|
|
23
|
+
implementation = lambda {}
|
|
24
|
+
RSpec.world.shared_example_groups.should_receive(:[]=).with("name", implementation)
|
|
25
|
+
send(method_name, "name", &implementation)
|
|
26
|
+
end
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
context "given a symbol" do
|
|
30
|
+
it "captures the given symbol and block in the World's collection of shared example groups" do
|
|
31
|
+
implementation = lambda {}
|
|
32
|
+
RSpec.world.shared_example_groups.should_receive(:[]=).with(:name, implementation)
|
|
33
|
+
send(method_name, :name, &implementation)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
context "given a hash" do
|
|
38
|
+
it "delegates extend on configuration" do
|
|
39
|
+
implementation = Proc.new { def bar; 'bar'; end }
|
|
40
|
+
send(method_name, :foo => :bar, &implementation)
|
|
41
|
+
a = RSpec.configuration.include_or_extend_modules.first
|
|
42
|
+
a[0].should eq(:extend)
|
|
43
|
+
Class.new.extend(a[1]).new.bar.should eq('bar')
|
|
44
|
+
a[2].should eq(:foo => :bar)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
35
47
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
context "given a string and a hash" do
|
|
49
|
+
it "captures the given string and block in the World's collection of shared example groups" do
|
|
50
|
+
implementation = lambda {}
|
|
51
|
+
RSpec.world.shared_example_groups.should_receive(:[]=).with("name", implementation)
|
|
52
|
+
send(method_name, "name", :foo => :bar, &implementation)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "delegates extend on configuration" do
|
|
56
|
+
implementation = Proc.new { def bar; 'bar'; end }
|
|
57
|
+
send(method_name, "name", :foo => :bar, &implementation)
|
|
58
|
+
a = RSpec.configuration.include_or_extend_modules.first
|
|
59
|
+
a[0].should eq(:extend)
|
|
60
|
+
Class.new.extend(a[1]).new.bar.should eq('bar')
|
|
61
|
+
a[2].should eq(:foo => :bar)
|
|
40
62
|
end
|
|
41
63
|
end
|
|
42
|
-
group = ExampleGroup.describe('group') { include Cornucopia }
|
|
43
|
-
phantom_group = group.children.first
|
|
44
|
-
phantom_group.description.should eql("")
|
|
45
|
-
phantom_group.metadata[:shared_group_name].should eql('Cornucopia')
|
|
46
|
-
phantom_group.examples.length.should == 1
|
|
47
|
-
phantom_group.examples.first.metadata[:description].should == "is plentiful"
|
|
48
64
|
end
|
|
49
65
|
end
|
|
50
66
|
|
|
@@ -97,7 +113,7 @@ module RSpec::Core
|
|
|
97
113
|
group = ExampleGroup.describe("group") do
|
|
98
114
|
it_should_behave_like "thing", :value1, :value2
|
|
99
115
|
end
|
|
100
|
-
group.
|
|
116
|
+
group.run
|
|
101
117
|
|
|
102
118
|
passed_params.should == { :param1 => :value1, :param2 => :value2 }
|
|
103
119
|
end
|
|
@@ -135,7 +151,7 @@ module RSpec::Core
|
|
|
135
151
|
end
|
|
136
152
|
end
|
|
137
153
|
end
|
|
138
|
-
group.
|
|
154
|
+
group.run
|
|
139
155
|
|
|
140
156
|
scopes[0].should be(scopes[1])
|
|
141
157
|
end
|
|
@@ -148,5 +164,25 @@ module RSpec::Core
|
|
|
148
164
|
end.should raise_error(/Could not find shared example group named/)
|
|
149
165
|
end
|
|
150
166
|
end
|
|
167
|
+
|
|
168
|
+
describe "#share_as" do
|
|
169
|
+
it "is exposed to the global namespace" do
|
|
170
|
+
Kernel.should respond_to("share_as")
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
|
|
174
|
+
share_as('Cornucopia') do
|
|
175
|
+
it "is plentiful" do
|
|
176
|
+
5.should == 4
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
group = ExampleGroup.describe('group') { include Cornucopia }
|
|
180
|
+
phantom_group = group.children.first
|
|
181
|
+
phantom_group.description.should eql("")
|
|
182
|
+
phantom_group.metadata[:shared_group_name].should eql('Cornucopia')
|
|
183
|
+
phantom_group.examples.length.should == 1
|
|
184
|
+
phantom_group.examples.first.metadata[:description].should == "is plentiful"
|
|
185
|
+
end
|
|
186
|
+
end
|
|
151
187
|
end
|
|
152
188
|
end
|
|
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
module RSpec::Core
|
|
4
4
|
|
|
5
5
|
describe Subject do
|
|
6
|
+
before(:each) { RSpec.configuration.configure_expectation_framework }
|
|
6
7
|
|
|
7
8
|
describe "implicit subject" do
|
|
8
9
|
describe "with a class" do
|
|
@@ -32,6 +33,25 @@ module RSpec::Core
|
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
describe "explicit subject" do
|
|
36
|
+
[false, nil].each do |falsy_value|
|
|
37
|
+
context "with a value of #{falsy_value.inspect}" do
|
|
38
|
+
it "is evaluated once per example" do
|
|
39
|
+
group = ExampleGroup.describe(Array)
|
|
40
|
+
group.before do
|
|
41
|
+
Object.should_receive(:this_question?).once.and_return(falsy_value)
|
|
42
|
+
end
|
|
43
|
+
group.subject do
|
|
44
|
+
Object.this_question?
|
|
45
|
+
end
|
|
46
|
+
group.example do
|
|
47
|
+
subject
|
|
48
|
+
subject
|
|
49
|
+
end
|
|
50
|
+
group.run.should be_true, "expected subject block to be evaluated only once"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
35
55
|
describe "defined in a top level group" do
|
|
36
56
|
it "replaces the implicit subject in that group" do
|
|
37
57
|
group = ExampleGroup.describe(Array)
|
|
@@ -59,5 +79,121 @@ module RSpec::Core
|
|
|
59
79
|
end
|
|
60
80
|
end
|
|
61
81
|
end
|
|
82
|
+
|
|
83
|
+
context "using 'self' as an explicit subject" do
|
|
84
|
+
it "delegates matcher to the ExampleGroup" do
|
|
85
|
+
group = ExampleGroup.describe("group") do
|
|
86
|
+
subject { self }
|
|
87
|
+
def ok?; true; end
|
|
88
|
+
|
|
89
|
+
it { should eq(self) }
|
|
90
|
+
it { should be_ok }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
group.run.should be_true
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe "#its" do
|
|
98
|
+
subject do
|
|
99
|
+
Class.new do
|
|
100
|
+
def initialize
|
|
101
|
+
@call_count = 0
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def call_count
|
|
105
|
+
@call_count += 1
|
|
106
|
+
end
|
|
107
|
+
end.new
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context "with a call counter" do
|
|
111
|
+
its(:call_count) { should eq(1) }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "with nil value" do
|
|
115
|
+
subject do
|
|
116
|
+
Class.new do
|
|
117
|
+
def nil_value
|
|
118
|
+
nil
|
|
119
|
+
end
|
|
120
|
+
end.new
|
|
121
|
+
end
|
|
122
|
+
its(:nil_value) { should be_nil }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context "with nested attributes" do
|
|
126
|
+
subject do
|
|
127
|
+
Class.new do
|
|
128
|
+
def name
|
|
129
|
+
"John"
|
|
130
|
+
end
|
|
131
|
+
end.new
|
|
132
|
+
end
|
|
133
|
+
its("name") { should eq("John") }
|
|
134
|
+
its("name.size") { should eq(4) }
|
|
135
|
+
its("name.size.class") { should eq(Fixnum) }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
context "when it responds to #[]" do
|
|
139
|
+
subject do
|
|
140
|
+
Class.new do
|
|
141
|
+
def [](*objects)
|
|
142
|
+
objects.map do |object|
|
|
143
|
+
"#{object.class}: #{object.to_s}"
|
|
144
|
+
end.join("; ")
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def name
|
|
148
|
+
"George"
|
|
149
|
+
end
|
|
150
|
+
end.new
|
|
151
|
+
end
|
|
152
|
+
its([:a]) { should == 'Symbol: a' }
|
|
153
|
+
its(['a']) { should == 'String: a' }
|
|
154
|
+
its([:b, 'c', 4]) { should == 'Symbol: b; String: c; Fixnum: 4' }
|
|
155
|
+
its(:name) { should = "George" }
|
|
156
|
+
context "when referring to an attribute without the proper array syntax" do
|
|
157
|
+
context "it raises an error" do
|
|
158
|
+
its(:age) do
|
|
159
|
+
expect do
|
|
160
|
+
should eq(64)
|
|
161
|
+
end.to raise_error(NoMethodError)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
context "when it does not respond to #[]" do
|
|
168
|
+
subject { Object.new }
|
|
169
|
+
|
|
170
|
+
context "it raises an error" do
|
|
171
|
+
its([:a]) do
|
|
172
|
+
expect do
|
|
173
|
+
should == 'Symbol: a'
|
|
174
|
+
end.to raise_error(NoMethodError)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
context "calling and overriding super" do
|
|
180
|
+
it "calls to the subject defined in the parent group" do
|
|
181
|
+
group = ExampleGroup.describe(Array) do
|
|
182
|
+
subject { [1, 'a'] }
|
|
183
|
+
|
|
184
|
+
its(:last) { should == 'a' }
|
|
185
|
+
|
|
186
|
+
describe '.first' do
|
|
187
|
+
def subject; super().first; end
|
|
188
|
+
|
|
189
|
+
its(:next) { should == 2 }
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
group.run.should be_true
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
end
|
|
62
198
|
end
|
|
63
199
|
end
|
|
@@ -5,83 +5,95 @@ class Foo; end
|
|
|
5
5
|
|
|
6
6
|
module RSpec::Core
|
|
7
7
|
|
|
8
|
-
describe World do
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
group = RSpec::Core::ExampleGroup.describe("group") {}
|
|
18
|
-
@world.example_groups.should include(group)
|
|
8
|
+
describe RSpec::Core::World do
|
|
9
|
+
let(:configuration) { RSpec::Core::Configuration.new }
|
|
10
|
+
let(:world) { RSpec::Core::World.new(configuration) }
|
|
11
|
+
|
|
12
|
+
describe "#example_groups" do
|
|
13
|
+
it "contains all registered example groups" do
|
|
14
|
+
group = RSpec::Core::ExampleGroup.describe("group"){}
|
|
15
|
+
world.register(group)
|
|
16
|
+
world.example_groups.should include(group)
|
|
19
17
|
end
|
|
20
|
-
|
|
21
18
|
end
|
|
22
19
|
|
|
23
|
-
describe "
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
describe "#apply_inclusion_filters" do
|
|
21
|
+
let(:group1) {
|
|
22
|
+
RSpec::Core::ExampleGroup.describe(Bar, "find group-1",
|
|
23
|
+
{ :foo => 1, :color => 'blue', :feature => 'reporting' }
|
|
24
|
+
) {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let(:group2) {
|
|
28
|
+
RSpec::Core::ExampleGroup.describe(Bar, "find group-2",
|
|
29
|
+
{ :pending => true, :feature => 'reporting' }
|
|
30
|
+
) {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let(:group3) {
|
|
34
|
+
RSpec::Core::ExampleGroup.describe(Bar, "find group-3",
|
|
35
|
+
{ :array => [1,2,3,4], :color => 'blue' }
|
|
36
|
+
) {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let(:group4) {
|
|
40
|
+
RSpec::Core::ExampleGroup.describe(Foo, "find these examples") do
|
|
33
41
|
it('I have no options') {}
|
|
34
42
|
it("this is awesome", :awesome => true) {}
|
|
35
43
|
it("this is too", :awesome => true) {}
|
|
36
44
|
it("not so awesome", :awesome => false) {}
|
|
37
45
|
it("I also have no options") {}
|
|
38
46
|
end
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let(:example_groups) { [group1, group2, group3, group4] }
|
|
41
50
|
|
|
42
51
|
it "finds no groups when given no search parameters" do
|
|
43
|
-
|
|
52
|
+
world.apply_inclusion_filters([]).should == []
|
|
44
53
|
end
|
|
45
54
|
|
|
46
55
|
it "finds matching groups when filtering on :describes (described class or module)" do
|
|
47
|
-
|
|
56
|
+
world.apply_inclusion_filters(example_groups, :example_group => { :describes => Bar }).should == [group1, group2, group3]
|
|
48
57
|
end
|
|
49
58
|
|
|
50
59
|
it "finds matching groups when filtering on :description with text" do
|
|
51
|
-
|
|
60
|
+
world.apply_inclusion_filters(example_groups, :example_group => { :description => 'Bar find group-1' }).should == [group1]
|
|
52
61
|
end
|
|
53
62
|
|
|
54
63
|
it "finds matching groups when filtering on :description with a lambda" do
|
|
55
|
-
|
|
64
|
+
world.apply_inclusion_filters(example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should == [group1, group3]
|
|
56
65
|
end
|
|
57
66
|
|
|
58
67
|
it "finds matching groups when filtering on :description with a regular expression" do
|
|
59
|
-
|
|
68
|
+
world.apply_inclusion_filters(example_groups, :example_group => { :description => /find group/ }).should == [group1, group2, group3]
|
|
60
69
|
end
|
|
61
70
|
|
|
62
71
|
it "finds one group when searching for :pending => true" do
|
|
63
|
-
|
|
72
|
+
world.apply_inclusion_filters(example_groups, :pending => true ).should == [group2]
|
|
64
73
|
end
|
|
65
74
|
|
|
66
75
|
it "finds matching groups when filtering on arbitrary metadata with a number" do
|
|
67
|
-
|
|
76
|
+
world.apply_inclusion_filters(example_groups, :foo => 1 ).should == [group1]
|
|
68
77
|
end
|
|
69
78
|
|
|
70
79
|
it "finds matching groups when filtering on arbitrary metadata with an array" do
|
|
71
|
-
|
|
80
|
+
world.apply_inclusion_filters(example_groups, :array => [1,2,3,4]).should == [group3]
|
|
72
81
|
end
|
|
73
82
|
|
|
74
83
|
it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do
|
|
75
|
-
|
|
84
|
+
world.apply_inclusion_filters(example_groups, :array => [4,3,2,1]).should be_empty
|
|
76
85
|
end
|
|
77
86
|
|
|
78
87
|
it "finds matching examples when filtering on arbitrary metadata" do
|
|
79
|
-
|
|
88
|
+
world.apply_inclusion_filters(group4.examples, :awesome => true).should == [group4.examples[1], group4.examples[2]]
|
|
80
89
|
end
|
|
81
90
|
|
|
91
|
+
it "finds matching examples for example that match any of the filters" do
|
|
92
|
+
world.apply_inclusion_filters(group4.examples, :awesome => true, :something => :else).should == [group4.examples[1], group4.examples[2]]
|
|
93
|
+
end
|
|
82
94
|
end
|
|
83
95
|
|
|
84
|
-
describe "
|
|
96
|
+
describe "#apply_exclusion_filters" do
|
|
85
97
|
|
|
86
98
|
it "finds nothing if all describes match the exclusion filter" do
|
|
87
99
|
options = { :network_access => true }
|
|
@@ -91,15 +103,18 @@ module RSpec::Core
|
|
|
91
103
|
it("bar") {}
|
|
92
104
|
end
|
|
93
105
|
|
|
94
|
-
|
|
106
|
+
world.register(group1)
|
|
107
|
+
|
|
108
|
+
world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
|
|
95
109
|
|
|
96
110
|
group2 = ExampleGroup.describe(Bar, "find group-1") do
|
|
97
111
|
it("foo", :network_access => true) {}
|
|
98
112
|
it("bar") {}
|
|
99
113
|
end
|
|
100
114
|
|
|
101
|
-
|
|
115
|
+
world.register(group2)
|
|
102
116
|
|
|
117
|
+
world.apply_exclusion_filters(group2.examples, :network_access => true).should == [group2.examples.last]
|
|
103
118
|
end
|
|
104
119
|
|
|
105
120
|
it "finds nothing if a regexp matches the exclusion filter" do
|
|
@@ -107,57 +122,185 @@ module RSpec::Core
|
|
|
107
122
|
it("foo") {}
|
|
108
123
|
it("bar") {}
|
|
109
124
|
end
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
world.register(group)
|
|
126
|
+
world.apply_exclusion_filters(group.examples, :name => /exclude/).should == []
|
|
127
|
+
world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should == []
|
|
128
|
+
world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => {
|
|
113
129
|
:describes => lambda { |b| b == Bar } } ).should == []
|
|
114
130
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
131
|
+
world.apply_exclusion_filters(group.examples, :name => /exclude not/).should == group.examples
|
|
132
|
+
world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should == []
|
|
133
|
+
world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should == []
|
|
118
134
|
end
|
|
119
135
|
end
|
|
120
136
|
|
|
137
|
+
describe "#preceding_declaration_line (again)" do
|
|
138
|
+
|
|
139
|
+
let(:group) do
|
|
140
|
+
RSpec::Core::ExampleGroup.describe("group") do
|
|
141
|
+
|
|
142
|
+
example("example") {}
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
let(:second_group) do
|
|
148
|
+
RSpec::Core::ExampleGroup.describe("second_group") do
|
|
121
149
|
|
|
122
|
-
|
|
123
|
-
before(:each) do
|
|
124
|
-
@group1_line = 10
|
|
125
|
-
@group2_line = 20
|
|
126
|
-
@group2_example1_line = 30
|
|
127
|
-
@group2_example2_line = 40
|
|
150
|
+
example("second_example") {}
|
|
128
151
|
|
|
129
|
-
@group1 = RSpec::Core::ExampleGroup.describe(Bar, "group-1") { }
|
|
130
|
-
@group2 = RSpec::Core::ExampleGroup.describe(Bar, "group-2") do
|
|
131
|
-
it('example 1') {}
|
|
132
|
-
it("example 2") {}
|
|
133
152
|
end
|
|
134
|
-
@group1.metadata[:example_group][:line_number] = @group1_line
|
|
135
|
-
@group2.metadata[:example_group][:line_number] = @group2_line
|
|
136
|
-
@group2.examples[0].metadata[:line_number] = @group2_example1_line
|
|
137
|
-
@group2.examples[1].metadata[:line_number] = @group2_example2_line
|
|
138
153
|
end
|
|
139
154
|
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
let(:group_declaration_line) { group.metadata[:example_group][:line_number] }
|
|
156
|
+
let(:example_declaration_line) { group_declaration_line + 2 }
|
|
157
|
+
|
|
158
|
+
context "with one example" do
|
|
159
|
+
before { world.register(group) }
|
|
160
|
+
|
|
161
|
+
it "returns nil if no example or group precedes the line" do
|
|
162
|
+
world.preceding_declaration_line(group_declaration_line - 1).should be_nil
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "returns the argument line number if a group starts on that line" do
|
|
166
|
+
world.preceding_declaration_line(group_declaration_line).should eq(group_declaration_line)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "returns the argument line number if an example starts on that line" do
|
|
170
|
+
world.preceding_declaration_line(example_declaration_line).should eq(example_declaration_line)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "returns line number of a group that immediately precedes the argument line" do
|
|
174
|
+
world.preceding_declaration_line(group_declaration_line + 1).should eq(group_declaration_line)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "returns line number of an example that immediately precedes the argument line" do
|
|
178
|
+
world.preceding_declaration_line(example_declaration_line + 1).should eq(example_declaration_line)
|
|
179
|
+
end
|
|
142
180
|
end
|
|
143
181
|
|
|
144
|
-
|
|
145
|
-
|
|
182
|
+
context "with two exaples and the second example is registre first" do
|
|
183
|
+
let(:second_group_declaration_line) { second_group.metadata[:example_group][:line_number] }
|
|
184
|
+
|
|
185
|
+
before do
|
|
186
|
+
world.register(second_group)
|
|
187
|
+
world.register(group)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'return line number of group if a group start on that line' do
|
|
191
|
+
world.preceding_declaration_line(second_group_declaration_line).should eq(second_group_declaration_line)
|
|
192
|
+
end
|
|
146
193
|
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe "#announce_filters" do
|
|
197
|
+
let(:reporter) { double('reporter').as_null_object }
|
|
198
|
+
before { world.stub(:reporter) { reporter } }
|
|
199
|
+
|
|
200
|
+
context "with no examples" do
|
|
201
|
+
before { world.stub(:example_count) { 0 } }
|
|
202
|
+
|
|
203
|
+
context "with no filters" do
|
|
204
|
+
it "announces" do
|
|
205
|
+
reporter.should_receive(:message).
|
|
206
|
+
with("No examples found.")
|
|
207
|
+
world.announce_filters
|
|
208
|
+
end
|
|
209
|
+
end
|
|
147
210
|
|
|
148
|
-
|
|
149
|
-
|
|
211
|
+
context "with an inclusion filter" do
|
|
212
|
+
it "announces" do
|
|
213
|
+
configuration.inclusion_filter = { :foo => 'bar' }
|
|
214
|
+
reporter.should_receive(:message).
|
|
215
|
+
with("No examples matched #{{ :foo => 'bar' }.inspect}.")
|
|
216
|
+
world.announce_filters
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
context "with an inclusion filter and run_all_when_everything_filtered" do
|
|
221
|
+
it "announces" do
|
|
222
|
+
configuration.stub(:run_all_when_everything_filtered?) { true }
|
|
223
|
+
configuration.inclusion_filter = { :foo => 'bar' }
|
|
224
|
+
reporter.should_receive(:message).
|
|
225
|
+
with("No examples matched #{{ :foo => 'bar' }.inspect}. Running all.")
|
|
226
|
+
world.announce_filters
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
context "with an exclusion filter" do
|
|
231
|
+
it "announces" do
|
|
232
|
+
configuration.exclusion_filter = { :foo => 'bar' }
|
|
233
|
+
reporter.should_receive(:message).
|
|
234
|
+
with("No examples were matched. Perhaps #{{ :foo => 'bar' }.inspect} is excluding everything?")
|
|
235
|
+
world.announce_filters
|
|
236
|
+
end
|
|
237
|
+
end
|
|
150
238
|
end
|
|
151
239
|
|
|
152
|
-
|
|
153
|
-
|
|
240
|
+
context "with examples" do
|
|
241
|
+
before { world.stub(:example_count) { 1 } }
|
|
242
|
+
|
|
243
|
+
context "with no filters" do
|
|
244
|
+
it "does not announce" do
|
|
245
|
+
reporter.should_not_receive(:message)
|
|
246
|
+
world.announce_filters
|
|
247
|
+
end
|
|
248
|
+
end
|
|
154
249
|
end
|
|
250
|
+
end
|
|
155
251
|
|
|
156
|
-
|
|
157
|
-
|
|
252
|
+
describe "#inclusion_filter" do
|
|
253
|
+
describe "#description" do
|
|
254
|
+
it 'cleans up the description' do
|
|
255
|
+
# check the assumptions of this example
|
|
256
|
+
project_dir = File.expand_path('.')
|
|
257
|
+
lambda { }.inspect.should include(project_dir)
|
|
258
|
+
lambda { }.inspect.should include('0x')
|
|
259
|
+
lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9'
|
|
260
|
+
|
|
261
|
+
configuration.filter_run :foo => lambda { }
|
|
262
|
+
world.inclusion_filter.description.should_not include('0x')
|
|
263
|
+
world.inclusion_filter.description.should_not include(project_dir)
|
|
264
|
+
world.inclusion_filter.description.should_not include(' (lambda)')
|
|
265
|
+
end
|
|
158
266
|
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
describe "#exclusion_filter" do
|
|
270
|
+
describe "#description" do
|
|
271
|
+
it 'returns `{}` when it only contains the default filters' do
|
|
272
|
+
world.exclusion_filter.description.should == {}.inspect
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it 'includes other filters' do
|
|
276
|
+
configuration.exclusion_filter[:foo] = :bar
|
|
277
|
+
world.exclusion_filter.description.should == { :foo => :bar }.inspect
|
|
278
|
+
end
|
|
159
279
|
|
|
280
|
+
it 'includes an overriden :if filter' do
|
|
281
|
+
configuration.exclusion_filter[:if] = :custom_filter
|
|
282
|
+
world.exclusion_filter.description.should == { :if => :custom_filter }.inspect
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it 'includes an overriden :unless filter' do
|
|
286
|
+
configuration.exclusion_filter[:unless] = :custom_filter
|
|
287
|
+
world.exclusion_filter.description.should == { :unless => :custom_filter }.inspect
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it 'cleans up the description' do
|
|
291
|
+
# check the assumptions of this example
|
|
292
|
+
project_dir = File.expand_path('.')
|
|
293
|
+
lambda { }.inspect.should include(project_dir)
|
|
294
|
+
lambda { }.inspect.should include('0x')
|
|
295
|
+
lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9'
|
|
296
|
+
|
|
297
|
+
configuration.exclusion_filter[:foo] = lambda { }
|
|
298
|
+
configuration.filter_run_excluding :bar => lambda { }
|
|
299
|
+
world.exclusion_filter.description.should_not include('0x')
|
|
300
|
+
world.exclusion_filter.description.should_not include(project_dir)
|
|
301
|
+
world.exclusion_filter.description.should_not include(' (lambda)')
|
|
302
|
+
end
|
|
303
|
+
end
|
|
160
304
|
end
|
|
161
305
|
end
|
|
162
|
-
|
|
163
306
|
end
|