rspec-core 2.14.8 → 2.99.0.beta1
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.
- checksums.yaml +8 -8
- data/Changelog.md +54 -8
- data/features/command_line/order.feature +5 -8
- data/features/configuration/custom_settings.feature +10 -10
- data/features/configuration/deprecation_stream.feature +3 -3
- data/features/configuration/read_options_from_file.feature +1 -1
- data/features/example_groups/shared_examples.feature +2 -2
- data/features/hooks/around_hooks.feature +1 -1
- data/features/metadata/current_example.feature +43 -4
- data/features/metadata/user_defined.feature +12 -12
- data/lib/autotest/rspec2.rb +60 -56
- data/lib/rspec/core.rb +40 -2
- data/lib/rspec/core/caller_filter.rb +55 -0
- data/lib/rspec/core/command_line.rb +2 -2
- data/lib/rspec/core/configuration.rb +201 -13
- data/lib/rspec/core/deprecation.rb +2 -7
- data/lib/rspec/core/example.rb +5 -8
- data/lib/rspec/core/example_group.rb +101 -17
- data/lib/rspec/core/filter_manager.rb +2 -2
- data/lib/rspec/core/formatters/deprecation_formatter.rb +173 -15
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -12
- data/lib/rspec/core/hooks.rb +1 -1
- data/lib/rspec/core/memoized_helpers.rb +49 -17
- data/lib/rspec/core/metadata.rb +1 -1
- data/lib/rspec/core/option_parser.rb +8 -3
- data/lib/rspec/core/pending.rb +14 -10
- data/lib/rspec/core/rake_task.rb +30 -6
- data/lib/rspec/core/runner.rb +9 -0
- data/lib/rspec/core/shared_example_group.rb +11 -9
- data/lib/rspec/core/shared_example_group/collection.rb +3 -1
- data/lib/rspec/core/version.rb +1 -2
- data/spec/command_line/order_spec.rb +4 -4
- data/spec/rspec/core/backtrace_cleaner_spec.rb +10 -10
- data/spec/rspec/core/caller_filter_spec.rb +58 -0
- data/spec/rspec/core/command_line_spec.rb +1 -0
- data/spec/rspec/core/configuration_options_spec.rb +6 -6
- data/spec/rspec/core/configuration_spec.rb +285 -52
- data/spec/rspec/core/deprecation_spec.rb +10 -29
- data/spec/rspec/core/deprecations_spec.rb +0 -14
- data/spec/rspec/core/example_group_spec.rb +74 -56
- data/spec/rspec/core/example_spec.rb +54 -17
- data/spec/rspec/core/filter_manager_spec.rb +2 -2
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +156 -52
- data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -1
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -2
- data/spec/rspec/core/hooks_spec.rb +2 -0
- data/spec/rspec/core/memoized_helpers_spec.rb +154 -113
- data/spec/rspec/core/metadata_spec.rb +25 -25
- data/spec/rspec/core/option_parser_spec.rb +19 -1
- data/spec/rspec/core/project_initializer_spec.rb +4 -4
- data/spec/rspec/core/rake_task_spec.rb +25 -4
- data/spec/rspec/core/shared_context_spec.rb +4 -4
- data/spec/rspec/core/shared_example_group_spec.rb +1 -1
- data/spec/rspec/core_spec.rb +36 -2
- data/spec/spec_helper.rb +3 -0
- data/spec/support/helper_methods.rb +16 -1
- data/spec/support/shared_example_groups.rb +1 -0
- data/spec/support/silence_dsl_deprecations.rb +32 -0
- metadata +10 -7
- data/spec/rspec/core/formatters/text_mate_formatted-2.1.0.html +0 -425
@@ -2,38 +2,19 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe RSpec::Core::Deprecation do
|
4
4
|
describe "#deprecate" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
RSpec.deprecate("deprecated_method")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "includes the replacement when provided" do
|
12
|
-
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
|
13
|
-
RSpec.deprecate("deprecated_method", "replacement")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "adds the call site" do
|
17
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
18
|
-
RSpec.deprecate("deprecated_method")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "doesn't override the existing callsite" do
|
22
|
-
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :call_site => "/path")
|
23
|
-
RSpec.deprecate("deprecated_method", :call_site => "/path")
|
24
|
-
end
|
5
|
+
it "passes the hash to the reporter" do
|
6
|
+
expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
|
7
|
+
RSpec.deprecate("deprecated_method", :replacement => "replacement")
|
25
8
|
end
|
26
9
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
10
|
+
it "adds the call site" do
|
11
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
12
|
+
RSpec.deprecate("deprecated_method")
|
13
|
+
end
|
32
14
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
15
|
+
it "doesn't override a passed call site" do
|
16
|
+
expect_deprecation_with_call_site("some_file.rb", 17)
|
17
|
+
RSpec.deprecate("deprecated_method", :call_site => "/some_file.rb:17")
|
37
18
|
end
|
38
19
|
end
|
39
20
|
|
@@ -23,20 +23,6 @@ describe "deprecated methods" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe RSpec::Core::ExampleGroup do
|
27
|
-
describe 'running_example' do
|
28
|
-
it 'is deprecated' do
|
29
|
-
RSpec.should_receive(:deprecate).at_least(:once)
|
30
|
-
self.running_example
|
31
|
-
end
|
32
|
-
|
33
|
-
it "delegates to example" do
|
34
|
-
RSpec.stub(:deprecate)
|
35
|
-
expect(running_example).to eq(example)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
26
|
describe RSpec::Core::SharedExampleGroup do
|
41
27
|
describe 'share_as' do
|
42
28
|
it 'is deprecated' do
|
@@ -29,6 +29,7 @@ module RSpec::Core
|
|
29
29
|
|
30
30
|
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false' do
|
31
31
|
before(:each) do
|
32
|
+
allow_deprecation
|
32
33
|
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
|
33
34
|
end
|
34
35
|
|
@@ -65,8 +66,8 @@ module RSpec::Core
|
|
65
66
|
examples_run = []
|
66
67
|
group = ExampleGroup.describe("parent") do
|
67
68
|
describe("child") do
|
68
|
-
it "does something" do
|
69
|
-
examples_run <<
|
69
|
+
it "does something" do |ex|
|
70
|
+
examples_run << ex
|
70
71
|
end
|
71
72
|
end
|
72
73
|
end
|
@@ -79,13 +80,13 @@ module RSpec::Core
|
|
79
80
|
it "runs its children " do
|
80
81
|
examples_run = []
|
81
82
|
group = ExampleGroup.describe("parent") do
|
82
|
-
it "fails" do
|
83
|
-
examples_run <<
|
83
|
+
it "fails" do |ex|
|
84
|
+
examples_run << ex
|
84
85
|
raise "fail"
|
85
86
|
end
|
86
87
|
describe("child") do
|
87
|
-
it "does something" do
|
88
|
-
examples_run <<
|
88
|
+
it "does something" do |ex|
|
89
|
+
examples_run << ex
|
89
90
|
end
|
90
91
|
end
|
91
92
|
end
|
@@ -298,7 +299,7 @@ module RSpec::Core
|
|
298
299
|
end
|
299
300
|
end
|
300
301
|
|
301
|
-
expect(group.run).to
|
302
|
+
expect(group.run).to be_truthy
|
302
303
|
end
|
303
304
|
end
|
304
305
|
|
@@ -314,7 +315,7 @@ module RSpec::Core
|
|
314
315
|
end
|
315
316
|
end
|
316
317
|
|
317
|
-
expect(group.run).to
|
318
|
+
expect(group.run).to be_truthy
|
318
319
|
end
|
319
320
|
end
|
320
321
|
end
|
@@ -329,7 +330,7 @@ module RSpec::Core
|
|
329
330
|
end
|
330
331
|
end
|
331
332
|
|
332
|
-
expect(group.run).to
|
333
|
+
expect(group.run).to be_truthy, "expected examples in group to pass"
|
333
334
|
end
|
334
335
|
end
|
335
336
|
|
@@ -402,11 +403,11 @@ module RSpec::Core
|
|
402
403
|
let(:focused_example) { ExampleGroup.describe.send example_alias, "a focused example" }
|
403
404
|
|
404
405
|
it 'defines an example that can be filtered with :focused => true' do
|
405
|
-
expect(focused_example.metadata[:focused]).to
|
406
|
+
expect(focused_example.metadata[:focused]).to be_truthy
|
406
407
|
end
|
407
408
|
|
408
409
|
it 'defines an example that can be filtered with :focus => true' do
|
409
|
-
expect(focused_example.metadata[:focus]).to
|
410
|
+
expect(focused_example.metadata[:focus]).to be_truthy
|
410
411
|
end
|
411
412
|
end
|
412
413
|
end
|
@@ -431,7 +432,7 @@ module RSpec::Core
|
|
431
432
|
group.example("example") {}
|
432
433
|
|
433
434
|
group.run
|
434
|
-
expect(RSpec.wants_to_quit).to
|
435
|
+
expect(RSpec.wants_to_quit).to be_falsey
|
435
436
|
end
|
436
437
|
|
437
438
|
it "runs the before eachs in order" do
|
@@ -594,7 +595,7 @@ module RSpec::Core
|
|
594
595
|
group = ExampleGroup.describe
|
595
596
|
group.before(:all) { raise "error in before all" }
|
596
597
|
example = group.example("equality") { expect(1).to eq(2) }
|
597
|
-
expect(group.run).to
|
598
|
+
expect(group.run).to be_falsey
|
598
599
|
|
599
600
|
expect(example.metadata).not_to be_nil
|
600
601
|
expect(example.metadata[:execution_result]).not_to be_nil
|
@@ -673,19 +674,10 @@ module RSpec::Core
|
|
673
674
|
end
|
674
675
|
end
|
675
676
|
|
676
|
-
it "has no 'running example' within before(:all)" do
|
677
|
-
group = ExampleGroup.describe
|
678
|
-
running_example = :none
|
679
|
-
group.before(:all) { running_example = example }
|
680
|
-
group.example("no-op") { }
|
681
|
-
group.run
|
682
|
-
expect(running_example).to be(nil)
|
683
|
-
end
|
684
|
-
|
685
677
|
it "has access to example options within before(:each)" do
|
686
678
|
group = ExampleGroup.describe
|
687
679
|
option = nil
|
688
|
-
group.before(:each) { option =
|
680
|
+
group.before(:each) {|ex| option = ex.options[:data] }
|
689
681
|
group.example("no-op", :data => :sample) { }
|
690
682
|
group.run
|
691
683
|
expect(option).to eq(:sample)
|
@@ -694,20 +686,11 @@ module RSpec::Core
|
|
694
686
|
it "has access to example options within after(:each)" do
|
695
687
|
group = ExampleGroup.describe
|
696
688
|
option = nil
|
697
|
-
group.after(:each) { option =
|
689
|
+
group.after(:each) {|ex| option = ex.options[:data] }
|
698
690
|
group.example("no-op", :data => :sample) { }
|
699
691
|
group.run
|
700
692
|
expect(option).to eq(:sample)
|
701
693
|
end
|
702
|
-
|
703
|
-
it "has no 'running example' within after(:all)" do
|
704
|
-
group = ExampleGroup.describe
|
705
|
-
running_example = :none
|
706
|
-
group.after(:all) { running_example = example }
|
707
|
-
group.example("no-op") { }
|
708
|
-
group.run
|
709
|
-
expect(running_example).to be(nil)
|
710
|
-
end
|
711
694
|
end
|
712
695
|
|
713
696
|
%w[pending xit xspecify xexample].each do |method_name|
|
@@ -765,20 +748,20 @@ module RSpec::Core
|
|
765
748
|
describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
|
766
749
|
|
767
750
|
describe "A sample nested group", :nested_describe => "yep" do
|
768
|
-
it "sets the described class to the described class of the outer most group" do
|
769
|
-
expect(
|
751
|
+
it "sets the described class to the described class of the outer most group" do |ex|
|
752
|
+
expect(ex.example_group.described_class).to eq(ExampleGroup)
|
770
753
|
end
|
771
754
|
|
772
|
-
it "sets the description to 'A sample nested describe'" do
|
773
|
-
expect(
|
755
|
+
it "sets the description to 'A sample nested describe'" do |ex|
|
756
|
+
expect(ex.example_group.description).to eq('A sample nested group')
|
774
757
|
end
|
775
758
|
|
776
|
-
it "has top level metadata from the example_group and its parent groups" do
|
777
|
-
expect(
|
759
|
+
it "has top level metadata from the example_group and its parent groups" do |ex|
|
760
|
+
expect(ex.example_group.metadata).to include(:little_less_nested => 'yep', :nested_describe => 'yep')
|
778
761
|
end
|
779
762
|
|
780
|
-
it "exposes the parent metadata to the contained examples" do
|
781
|
-
expect(
|
763
|
+
it "exposes the parent metadata to the contained examples" do |ex|
|
764
|
+
expect(ex.metadata).to include(:little_less_nested => 'yep', :nested_describe => 'yep')
|
782
765
|
end
|
783
766
|
end
|
784
767
|
|
@@ -794,7 +777,7 @@ module RSpec::Core
|
|
794
777
|
example('ex 2') { expect(1).to eq(1) }
|
795
778
|
end
|
796
779
|
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
|
797
|
-
expect(group.run(reporter)).to
|
780
|
+
expect(group.run(reporter)).to be_truthy
|
798
781
|
end
|
799
782
|
|
800
783
|
it "returns false if any of the examples fail" do
|
@@ -803,7 +786,7 @@ module RSpec::Core
|
|
803
786
|
example('ex 2') { expect(1).to eq(2) }
|
804
787
|
end
|
805
788
|
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
|
806
|
-
expect(group.run(reporter)).to
|
789
|
+
expect(group.run(reporter)).to be_falsey
|
807
790
|
end
|
808
791
|
|
809
792
|
it "runs all examples, regardless of any of them failing" do
|
@@ -815,7 +798,7 @@ module RSpec::Core
|
|
815
798
|
group.filtered_examples.each do |example|
|
816
799
|
example.should_receive(:run)
|
817
800
|
end
|
818
|
-
expect(group.run(reporter)).to
|
801
|
+
expect(group.run(reporter)).to be_falsey
|
819
802
|
end
|
820
803
|
end
|
821
804
|
|
@@ -836,12 +819,12 @@ module RSpec::Core
|
|
836
819
|
expect(@before_all_top_level).to eq('before_all_top_level')
|
837
820
|
end
|
838
821
|
|
839
|
-
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
|
840
|
-
expect(
|
822
|
+
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do |ex|
|
823
|
+
expect(ex.example_group.before_all_ivars).to include('@before_all_top_level' => 'before_all_top_level')
|
841
824
|
end
|
842
825
|
|
843
|
-
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
|
844
|
-
expect(
|
826
|
+
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do |ex|
|
827
|
+
expect(ex.example_group.before_all_ivars).to include(:@before_all_top_level => 'before_all_top_level')
|
845
828
|
end
|
846
829
|
|
847
830
|
describe "but now I am nested" do
|
@@ -869,12 +852,12 @@ module RSpec::Core
|
|
869
852
|
describe "ivars are not shared across examples" do
|
870
853
|
it "(first example)" do
|
871
854
|
@a = 1
|
872
|
-
expect(defined?(@b)).to
|
855
|
+
expect(defined?(@b)).to be_falsey
|
873
856
|
end
|
874
857
|
|
875
858
|
it "(second example)" do
|
876
859
|
@b = 2
|
877
|
-
expect(defined?(@a)).to
|
860
|
+
expect(defined?(@a)).to be_falsey
|
878
861
|
end
|
879
862
|
end
|
880
863
|
|
@@ -917,8 +900,8 @@ module RSpec::Core
|
|
917
900
|
it "sets RSpec.wants_to_quit flag if encountering an exception in before(:all)" do
|
918
901
|
group.before(:all) { raise "error in before all" }
|
919
902
|
group.example("equality") { expect(1).to eq(2) }
|
920
|
-
expect(group.run).to
|
921
|
-
expect(RSpec.wants_to_quit).to
|
903
|
+
expect(group.run).to be_falsey
|
904
|
+
expect(RSpec.wants_to_quit).to be_truthy
|
922
905
|
end
|
923
906
|
end
|
924
907
|
|
@@ -964,7 +947,7 @@ module RSpec::Core
|
|
964
947
|
end
|
965
948
|
end
|
966
949
|
|
967
|
-
expect(group.run(reporter)).to
|
950
|
+
expect(group.run(reporter)).to be_truthy
|
968
951
|
end
|
969
952
|
end
|
970
953
|
|
@@ -981,7 +964,7 @@ module RSpec::Core
|
|
981
964
|
end
|
982
965
|
end
|
983
966
|
|
984
|
-
expect(group.run(reporter)).to
|
967
|
+
expect(group.run(reporter)).to be_falsey
|
985
968
|
end
|
986
969
|
end
|
987
970
|
|
@@ -998,7 +981,7 @@ module RSpec::Core
|
|
998
981
|
end
|
999
982
|
end
|
1000
983
|
|
1001
|
-
expect(group.run(reporter)).to
|
984
|
+
expect(group.run(reporter)).to be_falsey
|
1002
985
|
end
|
1003
986
|
end
|
1004
987
|
end
|
@@ -1070,7 +1053,42 @@ module RSpec::Core
|
|
1070
1053
|
def foo; "bar"; end
|
1071
1054
|
end
|
1072
1055
|
end
|
1073
|
-
expect(group.run).to
|
1056
|
+
expect(group.run).to be_truthy
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
it "warns when extra args are submitted to a zero-arity shared block", :if => RUBY_VERSION.to_f >= 1.9 do
|
1060
|
+
group = ExampleGroup.describe
|
1061
|
+
group.shared_examples("named this") {}
|
1062
|
+
|
1063
|
+
expect(group).to receive(:warn) {|message|
|
1064
|
+
expect(message).to match(/expected 0 args/)
|
1065
|
+
expect(message).to match(/called from #{__FILE__}:#{__LINE__ + 2}/)
|
1066
|
+
}
|
1067
|
+
group.send(name, "named this", "extra arg")
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
it "warns with usage message when 2nd arg is the name of another shared group", :if => RUBY_VERSION.to_f >= 1.9 do
|
1071
|
+
group = ExampleGroup.describe
|
1072
|
+
group.shared_examples("named this") {}
|
1073
|
+
group.shared_examples("named that") {}
|
1074
|
+
|
1075
|
+
expect(group).to receive(:warn) {|message|
|
1076
|
+
expect(message).to match(/shared (context|examples) supports? the name of only one example group, received \["named this", "named that"\]/)
|
1077
|
+
expect(message).to match(/called from #{__FILE__}:#{__LINE__ + 2}/)
|
1078
|
+
}
|
1079
|
+
group.send(name, "named this", "named that")
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
it 'does not warn when the shared example group has a default arg', :if => RUBY_VERSION.to_f >= 1.9 do
|
1083
|
+
group = ExampleGroup.describe
|
1084
|
+
|
1085
|
+
# 1.8.7 can't parse blocks with arg defaults, so we have to eval it
|
1086
|
+
# to delay when it is parsed.
|
1087
|
+
eval('group.shared_examples("named this") { |opts={}| }')
|
1088
|
+
|
1089
|
+
expect(group).not_to receive(:warn)
|
1090
|
+
|
1091
|
+
group.send(name, "named this", :foo => 1)
|
1074
1092
|
end
|
1075
1093
|
end
|
1076
1094
|
end
|
@@ -27,13 +27,15 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
27
27
|
$stdout = orig_stdout
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "can be pretty printed" do
|
31
31
|
output = ignoring_warnings { capture_stdout { pp example_instance } }
|
32
32
|
expect(output).to include("RSpec::Core::Example")
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "#exception" do
|
36
36
|
it "supplies the first exception raised, if any" do
|
37
|
+
RSpec.configuration.output_stream = StringIO.new
|
38
|
+
|
37
39
|
example = example_group.example { raise "first" }
|
38
40
|
example_group.after { raise "second" }
|
39
41
|
example_group.run
|
@@ -150,26 +152,26 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
153
|
-
describe
|
155
|
+
describe "#described_class" do
|
154
156
|
it "returns the class (if any) of the outermost example group" do
|
155
157
|
expect(described_class).to eq(RSpec::Core::Example)
|
156
158
|
end
|
157
159
|
end
|
158
160
|
|
159
161
|
describe "accessing metadata within a running example" do
|
160
|
-
it "has a reference to itself when running" do
|
161
|
-
expect(
|
162
|
+
it "has a reference to itself when running" do |ex|
|
163
|
+
expect(ex.description).to eq("has a reference to itself when running")
|
162
164
|
end
|
163
165
|
|
164
|
-
it "can access the example group's top level metadata as if it were its own" do
|
165
|
-
expect(
|
166
|
-
expect(
|
166
|
+
it "can access the example group's top level metadata as if it were its own" do |ex|
|
167
|
+
expect(ex.example_group.metadata).to include(:parent_metadata => 'sample')
|
168
|
+
expect(ex.metadata).to include(:parent_metadata => 'sample')
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
170
172
|
describe "accessing options within a running example" do
|
171
|
-
it "can look up option values by key", :demo => :data do
|
172
|
-
expect(
|
173
|
+
it "can look up option values by key", :demo => :data do |ex|
|
174
|
+
expect(ex.metadata[:demo]).to eq(:data)
|
173
175
|
end
|
174
176
|
end
|
175
177
|
|
@@ -189,7 +191,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
189
191
|
example('example') { expect(1).to eq(1) }
|
190
192
|
end
|
191
193
|
group.run
|
192
|
-
expect(after_run).to
|
194
|
+
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
193
195
|
end
|
194
196
|
|
195
197
|
it "runs after(:each) when the example fails" do
|
@@ -199,7 +201,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
199
201
|
example('example') { expect(1).to eq(2) }
|
200
202
|
end
|
201
203
|
group.run
|
202
|
-
expect(after_run).to
|
204
|
+
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
203
205
|
end
|
204
206
|
|
205
207
|
it "runs after(:each) when the example raises an Exception" do
|
@@ -209,7 +211,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
209
211
|
example('example') { raise "this error" }
|
210
212
|
end
|
211
213
|
group.run
|
212
|
-
expect(after_run).to
|
214
|
+
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
213
215
|
end
|
214
216
|
|
215
217
|
context "with an after(:each) that raises" do
|
@@ -221,7 +223,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
221
223
|
example('example') { expect(1).to eq(1) }
|
222
224
|
end
|
223
225
|
group.run
|
224
|
-
expect(after_run).to
|
226
|
+
expect(after_run).to be_truthy, "expected after(:each) to be run"
|
225
227
|
end
|
226
228
|
|
227
229
|
it "stores the exception" do
|
@@ -270,7 +272,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
270
272
|
expect(@before_all).to eq(:before_all)
|
271
273
|
expect(@before_each).to eq(:before_each)
|
272
274
|
end
|
273
|
-
expect(group.run(double.as_null_object)).to
|
275
|
+
expect(group.run(double.as_null_object)).to be_truthy
|
274
276
|
group.new do |example|
|
275
277
|
%w[@before_all @before_each @after_each @after_all].each do |ivar|
|
276
278
|
expect(example.instance_variable_get(ivar)).to be_nil
|
@@ -284,7 +286,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
284
286
|
example("first") { expect(@before_all).not_to be_nil }
|
285
287
|
example("second") { expect(@before_all).not_to be_nil }
|
286
288
|
end
|
287
|
-
expect(group.run).to
|
289
|
+
expect(group.run).to be_truthy
|
288
290
|
end
|
289
291
|
end
|
290
292
|
|
@@ -319,7 +321,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
319
321
|
expect(message).to match(/An error occurred in an after.* hook/i)
|
320
322
|
end
|
321
323
|
|
322
|
-
it
|
324
|
+
it "does not print mock expectation errors" do
|
323
325
|
group = RSpec::Core::ExampleGroup.describe do
|
324
326
|
example do
|
325
327
|
foo = double
|
@@ -448,7 +450,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
448
450
|
end
|
449
451
|
end
|
450
452
|
|
451
|
-
it
|
453
|
+
it "does not interfere with per-example randomness when running examples in a random order" do
|
452
454
|
values = []
|
453
455
|
|
454
456
|
RSpec.configuration.order = :random
|
@@ -462,4 +464,39 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
462
464
|
|
463
465
|
expect(values.uniq).to have(2).values
|
464
466
|
end
|
467
|
+
|
468
|
+
describe "optional block argument" do
|
469
|
+
it "contains the example" do |ex|
|
470
|
+
expect(ex).to be_an(RSpec::Core::Example)
|
471
|
+
expect(ex.description).to match(/contains the example/)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
%w[example running_example].each do |accessor|
|
476
|
+
describe accessor do
|
477
|
+
before { allow_deprecation }
|
478
|
+
|
479
|
+
it "is deprecated" do
|
480
|
+
expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{accessor}/)
|
481
|
+
send(accessor)
|
482
|
+
end
|
483
|
+
|
484
|
+
it "returns the current running example" do |ex|
|
485
|
+
expect(send(accessor)).to eq ex
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
describe "setting the current example" do
|
491
|
+
it "sets RSpec.current_example to the example that is currently running" do
|
492
|
+
group = RSpec::Core::ExampleGroup.describe("an example group")
|
493
|
+
|
494
|
+
current_examples = []
|
495
|
+
example1 = group.example("example 1") { current_examples << RSpec.current_example }
|
496
|
+
example2 = group.example("example 2") { current_examples << RSpec.current_example }
|
497
|
+
|
498
|
+
group.run
|
499
|
+
expect(current_examples).to eq([example1, example2])
|
500
|
+
end
|
501
|
+
end
|
465
502
|
end
|