transpec 3.0.0 → 3.0.1
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 +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/transpec/version.rb +1 -1
- data/transpec.gemspec +4 -3
- metadata +3 -97
- data/spec/.rubocop.yml +0 -23
- data/spec/integration/configuration_modification_spec.rb +0 -186
- data/spec/integration/conversion_spec.rb +0 -145
- data/spec/spec_helper.rb +0 -52
- data/spec/support/cache_helper.rb +0 -62
- data/spec/support/file_helper.rb +0 -25
- data/spec/support/shared_context.rb +0 -84
- data/spec/transpec/cli_spec.rb +0 -341
- data/spec/transpec/commit_message_spec.rb +0 -81
- data/spec/transpec/config_spec.rb +0 -99
- data/spec/transpec/converter_spec.rb +0 -1374
- data/spec/transpec/directory_cloner_spec.rb +0 -74
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +0 -143
- data/spec/transpec/dynamic_analyzer_spec.rb +0 -329
- data/spec/transpec/git_spec.rb +0 -151
- data/spec/transpec/option_parser_spec.rb +0 -275
- data/spec/transpec/processed_source_spec.rb +0 -93
- data/spec/transpec/project_spec.rb +0 -194
- data/spec/transpec/record_spec.rb +0 -128
- data/spec/transpec/report_spec.rb +0 -126
- data/spec/transpec/rspec_version_spec.rb +0 -129
- data/spec/transpec/spec_file_finder_spec.rb +0 -118
- data/spec/transpec/spec_suite_spec.rb +0 -108
- data/spec/transpec/static_context_inspector_spec.rb +0 -713
- data/spec/transpec/syntax/allow_spec.rb +0 -122
- data/spec/transpec/syntax/be_boolean_spec.rb +0 -176
- data/spec/transpec/syntax/be_close_spec.rb +0 -51
- data/spec/transpec/syntax/current_example_spec.rb +0 -319
- data/spec/transpec/syntax/double_spec.rb +0 -175
- data/spec/transpec/syntax/example_group_spec.rb +0 -716
- data/spec/transpec/syntax/example_spec.rb +0 -301
- data/spec/transpec/syntax/expect_spec.rb +0 -313
- data/spec/transpec/syntax/have_spec.rb +0 -1276
- data/spec/transpec/syntax/hook_spec.rb +0 -215
- data/spec/transpec/syntax/its_spec.rb +0 -448
- data/spec/transpec/syntax/matcher_definition_spec.rb +0 -59
- data/spec/transpec/syntax/method_stub_spec.rb +0 -1301
- data/spec/transpec/syntax/oneliner_should_spec.rb +0 -628
- data/spec/transpec/syntax/operator_spec.rb +0 -871
- data/spec/transpec/syntax/pending_spec.rb +0 -415
- data/spec/transpec/syntax/raise_error_spec.rb +0 -354
- data/spec/transpec/syntax/receive_spec.rb +0 -499
- data/spec/transpec/syntax/rspec_configure_spec.rb +0 -870
- data/spec/transpec/syntax/should_receive_spec.rb +0 -1108
- data/spec/transpec/syntax/should_spec.rb +0 -497
- data/spec/transpec/util_spec.rb +0 -115
- data/spec/transpec_spec.rb +0 -22
@@ -1,129 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/rspec_version'
|
5
|
-
|
6
|
-
module Transpec
|
7
|
-
describe RSpecVersion do
|
8
|
-
subject(:rspec_version) { RSpecVersion.new(version_string) }
|
9
|
-
|
10
|
-
shared_examples 'version comparisons' do |method, expectations|
|
11
|
-
describe "##{method}" do
|
12
|
-
subject { rspec_version.send(method) }
|
13
|
-
|
14
|
-
expectations.each do |version, expected|
|
15
|
-
context "when the version is #{version}" do
|
16
|
-
let(:version_string) { version }
|
17
|
-
|
18
|
-
it "returns #{expected.inspect}" do
|
19
|
-
should be expected
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
[
|
27
|
-
:be_truthy_available?,
|
28
|
-
:yielded_example_available?,
|
29
|
-
:config_output_stream_available?,
|
30
|
-
:yielding_receiver_to_any_instance_implementation_block_available?
|
31
|
-
].each do |method|
|
32
|
-
include_examples 'version comparisons', method, [
|
33
|
-
['2.14.0', false],
|
34
|
-
['2.99.0.beta1', true],
|
35
|
-
['2.99.0.beta2', true],
|
36
|
-
['2.99.0.rc1', true],
|
37
|
-
['2.99.0', true],
|
38
|
-
['3.0.0.beta1', true],
|
39
|
-
['3.0.0.beta2', true],
|
40
|
-
['3.0.0.rc1', true],
|
41
|
-
['3.0.0', true]
|
42
|
-
]
|
43
|
-
end
|
44
|
-
|
45
|
-
[
|
46
|
-
:oneliner_is_expected_available?,
|
47
|
-
:skip_available?
|
48
|
-
].each do |method|
|
49
|
-
include_examples 'version comparisons', method, [
|
50
|
-
['2.14.0', false],
|
51
|
-
['2.99.0.beta1', false],
|
52
|
-
['2.99.0.beta2', true],
|
53
|
-
['2.99.0.rc1', true],
|
54
|
-
['2.99.0', true],
|
55
|
-
['3.0.0.beta1', false],
|
56
|
-
['3.0.0.beta2', true],
|
57
|
-
['3.0.0.rc1', true],
|
58
|
-
['3.0.0', true]
|
59
|
-
]
|
60
|
-
end
|
61
|
-
|
62
|
-
[
|
63
|
-
:config_pattern_available?,
|
64
|
-
:config_backtrace_formatter_available?,
|
65
|
-
:config_predicate_color_enabled_available?,
|
66
|
-
:config_predicate_warnings_available?,
|
67
|
-
:implicit_spec_type_disablement_available?
|
68
|
-
].each do |method|
|
69
|
-
include_examples 'version comparisons', method, [
|
70
|
-
['2.14.0', false],
|
71
|
-
['2.99.0.beta1', false],
|
72
|
-
['2.99.0.beta2', false],
|
73
|
-
['2.99.0.rc1', true],
|
74
|
-
['2.99.0', true],
|
75
|
-
['3.0.0.beta1', false],
|
76
|
-
['3.0.0.beta2', false],
|
77
|
-
['3.0.0.rc1', true],
|
78
|
-
['3.0.0', true]
|
79
|
-
]
|
80
|
-
end
|
81
|
-
|
82
|
-
[
|
83
|
-
:receive_messages_available?
|
84
|
-
].each do |method|
|
85
|
-
include_examples 'version comparisons', method, [
|
86
|
-
['2.14.0', false],
|
87
|
-
['2.99.0.beta1', false],
|
88
|
-
['2.99.0.beta2', false],
|
89
|
-
['2.99.0.rc1', false],
|
90
|
-
['2.99.0', false],
|
91
|
-
['3.0.0.beta1', true],
|
92
|
-
['3.0.0.beta2', true],
|
93
|
-
['3.0.0.rc1', true],
|
94
|
-
['3.0.0', true]
|
95
|
-
]
|
96
|
-
end
|
97
|
-
|
98
|
-
[
|
99
|
-
:receive_message_chain_available?,
|
100
|
-
:non_should_matcher_protocol_available?,
|
101
|
-
:non_monkey_patch_example_group_available?,
|
102
|
-
:hook_scope_alias_available?
|
103
|
-
].each do |method|
|
104
|
-
include_examples 'version comparisons', method, [
|
105
|
-
['2.14.0', false],
|
106
|
-
['2.99.0.beta1', false],
|
107
|
-
['2.99.0.beta2', false],
|
108
|
-
['2.99.0.rc1', false],
|
109
|
-
['2.99.0', false],
|
110
|
-
['3.0.0.beta1', false],
|
111
|
-
['3.0.0.beta2', true],
|
112
|
-
['3.0.0.rc1', true],
|
113
|
-
['3.0.0', true]
|
114
|
-
]
|
115
|
-
end
|
116
|
-
|
117
|
-
include_examples 'version comparisons', :rspec_2_99?, [
|
118
|
-
['2.14.0', false],
|
119
|
-
['2.99.0.beta1', true],
|
120
|
-
['2.99.0.beta2', true],
|
121
|
-
['2.99.0.rc1', true],
|
122
|
-
['2.99.0', true],
|
123
|
-
['3.0.0.beta1', false],
|
124
|
-
['3.0.0.beta2', false],
|
125
|
-
['3.0.0.rc1', false],
|
126
|
-
['3.0.0', false]
|
127
|
-
]
|
128
|
-
end
|
129
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/spec_file_finder'
|
5
|
-
|
6
|
-
module Transpec
|
7
|
-
describe SpecFileFinder do
|
8
|
-
include FileHelper
|
9
|
-
|
10
|
-
describe '.find' do
|
11
|
-
include_context 'isolated environment'
|
12
|
-
|
13
|
-
before do
|
14
|
-
['file', 'file.rb', 'dir/file', 'dir/file.rb'].each do |path|
|
15
|
-
create_file(path, '')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
subject { SpecFileFinder.find(paths) }
|
20
|
-
|
21
|
-
context 'when no path is passed' do
|
22
|
-
let(:paths) { [] }
|
23
|
-
|
24
|
-
context 'and there is "spec" directory' do
|
25
|
-
before do
|
26
|
-
create_file('spec/file.rb', '')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns file paths with .rb extension in the "spec" directory recursively' do
|
30
|
-
should == ['spec/file.rb']
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'and there is not "spec" directory' do
|
35
|
-
it 'raises error' do
|
36
|
-
-> { SpecFileFinder.find(paths) }.should raise_error(ArgumentError)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when a file path with .rb extension is passed' do
|
42
|
-
let(:paths) { ['file.rb'] }
|
43
|
-
|
44
|
-
it 'returns the path' do
|
45
|
-
should == ['file.rb']
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when a file path without extension is passed' do
|
50
|
-
let(:paths) { ['file'] }
|
51
|
-
|
52
|
-
it 'returns the path' do
|
53
|
-
should == ['file']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when a non-existent path is passed' do
|
58
|
-
let(:paths) { ['non-existent-file'] }
|
59
|
-
|
60
|
-
it 'raises error' do
|
61
|
-
-> { SpecFileFinder.find(paths) }.should raise_error(ArgumentError) { |error|
|
62
|
-
error.message.should == 'No such file or directory "non-existent-file"'
|
63
|
-
}
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when a directory path is passed' do
|
68
|
-
let(:paths) { ['dir'] }
|
69
|
-
|
70
|
-
it 'returns file paths with .rb extension in the directory recursively' do
|
71
|
-
should == ['dir/file.rb']
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe '.base_paths' do
|
77
|
-
include_context 'isolated environment'
|
78
|
-
|
79
|
-
subject { SpecFileFinder.base_paths(paths) }
|
80
|
-
|
81
|
-
context 'when target paths are specified' do
|
82
|
-
let(:paths) { ['foo_spec.rb', 'spec/bar_spec.rb'] }
|
83
|
-
|
84
|
-
it 'returns the passed paths' do
|
85
|
-
should == paths
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when paths outside of the current working directory are specified' do
|
90
|
-
let(:paths) { ['../foo_spec.rb', 'spec/bar_spec.rb'] }
|
91
|
-
|
92
|
-
it 'raises error' do
|
93
|
-
-> { SpecFileFinder.base_paths(paths) }.should raise_error(ArgumentError)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when no target paths are specified' do
|
98
|
-
let(:paths) { [] }
|
99
|
-
|
100
|
-
context 'and there is "spec" directory' do
|
101
|
-
before do
|
102
|
-
Dir.mkdir('spec')
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'returns ["spec"]' do
|
106
|
-
should == ['spec']
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'and there is not "spec" directory' do
|
111
|
-
it 'raises error' do
|
112
|
-
-> { SpecFileFinder.base_paths(paths) }.should raise_error(ArgumentError)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/spec_suite'
|
5
|
-
require 'transpec/dynamic_analyzer'
|
6
|
-
|
7
|
-
module Transpec
|
8
|
-
describe SpecSuite do
|
9
|
-
include FileHelper
|
10
|
-
include_context 'isolated environment'
|
11
|
-
|
12
|
-
subject(:spec_suite) { SpecSuite.new(project, target_paths, runtime_data) }
|
13
|
-
let(:project) { Project.new }
|
14
|
-
let(:target_paths) { [] }
|
15
|
-
let(:runtime_data) { nil }
|
16
|
-
|
17
|
-
describe '#need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?' do
|
18
|
-
subject do
|
19
|
-
spec_suite.need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
|
20
|
-
end
|
21
|
-
|
22
|
-
context "when there's an any_instance block to convert" do
|
23
|
-
before do
|
24
|
-
create_file('spec/example_spec.rb', <<-END)
|
25
|
-
describe 'example' do
|
26
|
-
it 'responds to #message' do
|
27
|
-
Object.any_instance.stub(:message) do |arg|
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
END
|
32
|
-
end
|
33
|
-
|
34
|
-
it { should be_true }
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when there's no any_instance block to convert" do
|
38
|
-
before do
|
39
|
-
create_file('spec/example_spec.rb', <<-END)
|
40
|
-
describe 'example' do
|
41
|
-
it 'responds to #message' do
|
42
|
-
Object.any_instance.stub(:message) do
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
END
|
47
|
-
end
|
48
|
-
|
49
|
-
it { should be_false }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#main_rspec_configure_node?' do
|
54
|
-
before do
|
55
|
-
create_file('spec/spec_helper.rb', <<-END)
|
56
|
-
RSpec.configure do |config|
|
57
|
-
end
|
58
|
-
END
|
59
|
-
|
60
|
-
create_file('spec/unit/spec_helper.rb', <<-END)
|
61
|
-
require 'spec_helper'
|
62
|
-
|
63
|
-
RSpec.configure do |config|
|
64
|
-
end
|
65
|
-
END
|
66
|
-
|
67
|
-
create_file('spec/unit/unit_spec.rb', <<-END)
|
68
|
-
require 'unit/spec_helper'
|
69
|
-
END
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'without runtime information' do
|
73
|
-
it 'returns true for every node' do
|
74
|
-
spec_suite.specs.each do |spec|
|
75
|
-
spec.ast.each_node do |node|
|
76
|
-
spec_suite.main_rspec_configure_node?(node).should be_true
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'with runtime information' do
|
83
|
-
let(:runtime_data) { Transpec::DynamicAnalyzer.new(silent: true).analyze(target_paths) }
|
84
|
-
|
85
|
-
let(:main_rspec_configure_node) do
|
86
|
-
spec_suite.specs.each do |spec|
|
87
|
-
next unless spec.path == 'spec/spec_helper.rb'
|
88
|
-
spec.ast.each_node(:send) do |send_node|
|
89
|
-
return send_node if send_node.children[1] == :configure
|
90
|
-
end
|
91
|
-
end
|
92
|
-
fail 'Main RSpec.configure node not found!'
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'returns true only for the main RSpec.configure node' do
|
96
|
-
spec_suite.main_rspec_configure_node?(main_rspec_configure_node).should be_true
|
97
|
-
|
98
|
-
spec_suite.specs.each do |spec|
|
99
|
-
spec.ast.each_node do |node|
|
100
|
-
next if node.equal?(main_rspec_configure_node)
|
101
|
-
spec_suite.main_rspec_configure_node?(node).should be_false
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,713 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/static_context_inspector'
|
5
|
-
require 'ast'
|
6
|
-
|
7
|
-
module Transpec
|
8
|
-
describe StaticContextInspector do
|
9
|
-
include CacheHelper
|
10
|
-
include ::AST::Sexp
|
11
|
-
include_context 'parsed objects'
|
12
|
-
include_context 'isolated environment'
|
13
|
-
|
14
|
-
describe '#scopes' do
|
15
|
-
def node_id(node)
|
16
|
-
id = node.type.to_s
|
17
|
-
node.children.each do |child|
|
18
|
-
break if child.is_a?(Parser::AST::Node)
|
19
|
-
id << " #{child.inspect}"
|
20
|
-
end
|
21
|
-
id
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:source) do
|
25
|
-
<<-END
|
26
|
-
top_level
|
27
|
-
|
28
|
-
RSpec.configure do |config|
|
29
|
-
config.before do
|
30
|
-
in_before
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module SomeModule
|
35
|
-
in_module
|
36
|
-
|
37
|
-
describe 'something' do
|
38
|
-
def some_method(some_arg)
|
39
|
-
do_something
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'is 1' do
|
43
|
-
in_example
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
1.times do
|
48
|
-
in_block
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
RSpec.describe 'something' do
|
53
|
-
in_rspec_describe
|
54
|
-
end
|
55
|
-
|
56
|
-
feature 'Capybara DSL' do
|
57
|
-
background do
|
58
|
-
in_background
|
59
|
-
end
|
60
|
-
|
61
|
-
given(:foo) do
|
62
|
-
in_given
|
63
|
-
end
|
64
|
-
|
65
|
-
scenario 'some page shows something' do
|
66
|
-
in_scenario
|
67
|
-
end
|
68
|
-
end
|
69
|
-
END
|
70
|
-
end
|
71
|
-
|
72
|
-
[
|
73
|
-
[
|
74
|
-
'send nil :top_level',
|
75
|
-
'in top level',
|
76
|
-
[]
|
77
|
-
], [
|
78
|
-
'send nil :in_before',
|
79
|
-
'in before block in RSpec.configure',
|
80
|
-
[:rspec_configure, :each_before_after]
|
81
|
-
], [
|
82
|
-
'module',
|
83
|
-
'at module definition in top level',
|
84
|
-
[]
|
85
|
-
], [
|
86
|
-
'const nil :SomeModule',
|
87
|
-
'at constant of module definition',
|
88
|
-
[]
|
89
|
-
], [
|
90
|
-
'send nil :in_module',
|
91
|
-
'in module',
|
92
|
-
[:module]
|
93
|
-
], [
|
94
|
-
'send nil :describe',
|
95
|
-
'at #describe in module',
|
96
|
-
[:module]
|
97
|
-
], [
|
98
|
-
'def :some_method',
|
99
|
-
'at method definition in #describe in module',
|
100
|
-
[:module, :example_group]
|
101
|
-
], [
|
102
|
-
'arg :some_arg',
|
103
|
-
'at method argument in #describe in module',
|
104
|
-
[:module, :example_group, :def]
|
105
|
-
], [
|
106
|
-
'send nil :do_something',
|
107
|
-
'in method in #describe in module',
|
108
|
-
[:module, :example_group, :def]
|
109
|
-
], [
|
110
|
-
'send nil :it',
|
111
|
-
'at #it in #describe in module',
|
112
|
-
[:module, :example_group]
|
113
|
-
], [
|
114
|
-
'str "is 1"',
|
115
|
-
"at #it's description in #describe in module",
|
116
|
-
[:module, :example_group]
|
117
|
-
], [
|
118
|
-
'send nil :in_example',
|
119
|
-
'#it in #describe in module',
|
120
|
-
[:module, :example_group, :example]
|
121
|
-
], [
|
122
|
-
'send nil :in_block',
|
123
|
-
'in normal block in #describe in module',
|
124
|
-
[:module]
|
125
|
-
], [
|
126
|
-
'send nil :in_rspec_describe',
|
127
|
-
'in RSpec.describe',
|
128
|
-
[:example_group]
|
129
|
-
], [
|
130
|
-
'send nil :in_background',
|
131
|
-
'in #background block in #feature',
|
132
|
-
[:example_group, :each_before_after]
|
133
|
-
], [
|
134
|
-
'send nil :in_given',
|
135
|
-
'in #given block in #feature',
|
136
|
-
[:example_group, :helper]
|
137
|
-
], [
|
138
|
-
'send nil :in_scenario',
|
139
|
-
'in #scenario block in #feature',
|
140
|
-
[:example_group, :example]
|
141
|
-
]
|
142
|
-
].each do |target_node_id, description, expected_scopes|
|
143
|
-
context "when #{description}" do
|
144
|
-
let(:target_node) do
|
145
|
-
ast.each_node.find do |node|
|
146
|
-
node_id(node) == target_node_id
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it "returns #{expected_scopes.inspect}" do
|
151
|
-
fail 'Target node is not found!' unless target_node
|
152
|
-
|
153
|
-
context_inspector = StaticContextInspector.new(target_node)
|
154
|
-
context_inspector.scopes.should == expected_scopes
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
shared_examples 'context inspection methods' do
|
161
|
-
let(:context_inspector) do
|
162
|
-
ast.each_node do |node|
|
163
|
-
next unless node == s(:send, nil, :target)
|
164
|
-
return StaticContextInspector.new(node)
|
165
|
-
end
|
166
|
-
|
167
|
-
fail 'Target node not found!'
|
168
|
-
end
|
169
|
-
|
170
|
-
def eval_with_rspec_in_context(eval_source, spec_source)
|
171
|
-
result_path = 'result'
|
172
|
-
|
173
|
-
helper_source = <<-END
|
174
|
-
def target
|
175
|
-
File.open(#{result_path.inspect}, 'w') do |file|
|
176
|
-
Marshal.dump(#{eval_source}, file)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
END
|
180
|
-
|
181
|
-
source_path = 'spec.rb'
|
182
|
-
|
183
|
-
File.write(source_path, helper_source + spec_source)
|
184
|
-
|
185
|
-
`rspec #{source_path}`
|
186
|
-
|
187
|
-
Marshal.load(File.read(result_path))
|
188
|
-
end
|
189
|
-
|
190
|
-
describe '#non_monkey_patch_expectation_available?' do
|
191
|
-
subject { context_inspector.non_monkey_patch_expectation_available? }
|
192
|
-
|
193
|
-
let(:expected) do
|
194
|
-
eval_source = 'respond_to?(:expect)'
|
195
|
-
with_cache(eval_source + source) do
|
196
|
-
eval_with_rspec_in_context(eval_source, source)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
it { should be expected }
|
201
|
-
end
|
202
|
-
|
203
|
-
describe '#non_monkey_patch_mock_available?' do
|
204
|
-
subject { context_inspector.non_monkey_patch_mock_available? }
|
205
|
-
|
206
|
-
let(:expected) do
|
207
|
-
eval_source = 'respond_to?(:allow) && respond_to?(:receive)'
|
208
|
-
with_cache(eval_source + source) do
|
209
|
-
eval_with_rspec_in_context(eval_source, source)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
it { should be expected }
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
context 'when in top level' do
|
218
|
-
let(:source) do
|
219
|
-
'target'
|
220
|
-
end
|
221
|
-
|
222
|
-
include_examples 'context inspection methods'
|
223
|
-
end
|
224
|
-
|
225
|
-
context 'when in an instance method in top level' do
|
226
|
-
let(:source) do
|
227
|
-
<<-END
|
228
|
-
def some_method
|
229
|
-
target
|
230
|
-
end
|
231
|
-
|
232
|
-
describe('test') { example { target } }
|
233
|
-
END
|
234
|
-
end
|
235
|
-
|
236
|
-
include_examples 'context inspection methods'
|
237
|
-
end
|
238
|
-
|
239
|
-
context 'when in a block in an instance method in top level' do
|
240
|
-
let(:source) do
|
241
|
-
<<-END
|
242
|
-
def some_method
|
243
|
-
1.times do
|
244
|
-
target
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe('test') { example { target } }
|
249
|
-
END
|
250
|
-
end
|
251
|
-
|
252
|
-
include_examples 'context inspection methods'
|
253
|
-
end
|
254
|
-
|
255
|
-
context 'when in #describe block in top level' do
|
256
|
-
let(:source) do
|
257
|
-
<<-END
|
258
|
-
describe 'foo' do
|
259
|
-
target
|
260
|
-
end
|
261
|
-
END
|
262
|
-
end
|
263
|
-
|
264
|
-
include_examples 'context inspection methods'
|
265
|
-
end
|
266
|
-
|
267
|
-
context 'when in an instance method in #describe block in top level' do
|
268
|
-
let(:source) do
|
269
|
-
<<-END
|
270
|
-
describe 'foo' do
|
271
|
-
def some_method
|
272
|
-
target
|
273
|
-
end
|
274
|
-
|
275
|
-
example { some_method }
|
276
|
-
end
|
277
|
-
END
|
278
|
-
end
|
279
|
-
|
280
|
-
include_examples 'context inspection methods'
|
281
|
-
end
|
282
|
-
|
283
|
-
context 'when in #it block in #describe block in top level' do
|
284
|
-
let(:source) do
|
285
|
-
<<-END
|
286
|
-
describe 'foo' do
|
287
|
-
it 'is an example' do
|
288
|
-
target
|
289
|
-
end
|
290
|
-
end
|
291
|
-
END
|
292
|
-
end
|
293
|
-
|
294
|
-
include_examples 'context inspection methods'
|
295
|
-
end
|
296
|
-
|
297
|
-
context 'when in #before block in #describe block in top level' do
|
298
|
-
let(:source) do
|
299
|
-
<<-END
|
300
|
-
describe 'foo' do
|
301
|
-
before do
|
302
|
-
target
|
303
|
-
end
|
304
|
-
|
305
|
-
example { }
|
306
|
-
end
|
307
|
-
END
|
308
|
-
end
|
309
|
-
|
310
|
-
include_examples 'context inspection methods'
|
311
|
-
end
|
312
|
-
|
313
|
-
context 'when in #before(:each) block in #describe block in top level' do
|
314
|
-
let(:source) do
|
315
|
-
<<-END
|
316
|
-
describe 'foo' do
|
317
|
-
before(:each) do
|
318
|
-
target
|
319
|
-
end
|
320
|
-
|
321
|
-
example { }
|
322
|
-
end
|
323
|
-
END
|
324
|
-
end
|
325
|
-
|
326
|
-
include_examples 'context inspection methods'
|
327
|
-
end
|
328
|
-
|
329
|
-
context 'when in #before(:all) block in #describe block in top level' do
|
330
|
-
let(:source) do
|
331
|
-
<<-END
|
332
|
-
describe 'foo' do
|
333
|
-
before(:all) do
|
334
|
-
target
|
335
|
-
end
|
336
|
-
|
337
|
-
example { }
|
338
|
-
end
|
339
|
-
END
|
340
|
-
end
|
341
|
-
|
342
|
-
include_examples 'context inspection methods'
|
343
|
-
end
|
344
|
-
|
345
|
-
context 'when in #after block in #describe block in top level' do
|
346
|
-
let(:source) do
|
347
|
-
<<-END
|
348
|
-
describe 'foo' do
|
349
|
-
after do
|
350
|
-
target
|
351
|
-
end
|
352
|
-
|
353
|
-
example { }
|
354
|
-
end
|
355
|
-
END
|
356
|
-
end
|
357
|
-
|
358
|
-
include_examples 'context inspection methods'
|
359
|
-
end
|
360
|
-
|
361
|
-
context 'when in #after(:each) block in #describe block in top level' do
|
362
|
-
let(:source) do
|
363
|
-
<<-END
|
364
|
-
describe 'foo' do
|
365
|
-
after(:each) do
|
366
|
-
target
|
367
|
-
end
|
368
|
-
|
369
|
-
example { }
|
370
|
-
end
|
371
|
-
END
|
372
|
-
end
|
373
|
-
|
374
|
-
include_examples 'context inspection methods'
|
375
|
-
end
|
376
|
-
|
377
|
-
context 'when in #after(:all) block in #describe block in top level' do
|
378
|
-
let(:source) do
|
379
|
-
<<-END
|
380
|
-
describe 'foo' do
|
381
|
-
after(:all) do
|
382
|
-
target
|
383
|
-
end
|
384
|
-
|
385
|
-
example { }
|
386
|
-
end
|
387
|
-
END
|
388
|
-
end
|
389
|
-
|
390
|
-
include_examples 'context inspection methods'
|
391
|
-
end
|
392
|
-
|
393
|
-
context 'when in #around block in #describe block in top level' do
|
394
|
-
let(:source) do
|
395
|
-
<<-END
|
396
|
-
describe 'foo' do
|
397
|
-
around do
|
398
|
-
target
|
399
|
-
end
|
400
|
-
|
401
|
-
example { }
|
402
|
-
end
|
403
|
-
END
|
404
|
-
end
|
405
|
-
|
406
|
-
include_examples 'context inspection methods'
|
407
|
-
end
|
408
|
-
|
409
|
-
context 'when in #subject block in #describe block in top level' do
|
410
|
-
let(:source) do
|
411
|
-
<<-END
|
412
|
-
describe 'foo' do
|
413
|
-
subject do
|
414
|
-
target
|
415
|
-
end
|
416
|
-
|
417
|
-
example { subject }
|
418
|
-
end
|
419
|
-
END
|
420
|
-
end
|
421
|
-
|
422
|
-
include_examples 'context inspection methods'
|
423
|
-
end
|
424
|
-
|
425
|
-
context 'when in #subject! block in #describe block in top level' do
|
426
|
-
let(:source) do
|
427
|
-
<<-END
|
428
|
-
describe 'foo' do
|
429
|
-
subject! do
|
430
|
-
target
|
431
|
-
end
|
432
|
-
|
433
|
-
example { subject }
|
434
|
-
end
|
435
|
-
END
|
436
|
-
end
|
437
|
-
|
438
|
-
include_examples 'context inspection methods'
|
439
|
-
end
|
440
|
-
|
441
|
-
context 'when in #let block in #describe block in top level' do
|
442
|
-
let(:source) do
|
443
|
-
<<-END
|
444
|
-
describe 'foo' do
|
445
|
-
let(:something) do
|
446
|
-
target
|
447
|
-
end
|
448
|
-
|
449
|
-
example { something }
|
450
|
-
end
|
451
|
-
END
|
452
|
-
end
|
453
|
-
|
454
|
-
include_examples 'context inspection methods'
|
455
|
-
end
|
456
|
-
|
457
|
-
context 'when in #let! block in #describe block in top level' do
|
458
|
-
let(:source) do
|
459
|
-
<<-END
|
460
|
-
describe 'foo' do
|
461
|
-
let!(:something) do
|
462
|
-
target
|
463
|
-
end
|
464
|
-
|
465
|
-
example { something }
|
466
|
-
end
|
467
|
-
END
|
468
|
-
end
|
469
|
-
|
470
|
-
include_examples 'context inspection methods'
|
471
|
-
end
|
472
|
-
|
473
|
-
context 'when in any other block in #describe block in top level' do
|
474
|
-
let(:source) do
|
475
|
-
<<-END
|
476
|
-
describe 'foo' do
|
477
|
-
1.times do
|
478
|
-
target
|
479
|
-
end
|
480
|
-
|
481
|
-
example { }
|
482
|
-
end
|
483
|
-
END
|
484
|
-
end
|
485
|
-
|
486
|
-
include_examples 'context inspection methods'
|
487
|
-
end
|
488
|
-
|
489
|
-
context 'when in #before block in singleton method with self in #describe block in top level' do
|
490
|
-
let(:source) do
|
491
|
-
<<-END
|
492
|
-
describe 'foo' do
|
493
|
-
def self.some_method
|
494
|
-
before do
|
495
|
-
target
|
496
|
-
end
|
497
|
-
end
|
498
|
-
|
499
|
-
some_method
|
500
|
-
|
501
|
-
example { something }
|
502
|
-
end
|
503
|
-
END
|
504
|
-
end
|
505
|
-
|
506
|
-
include_examples 'context inspection methods'
|
507
|
-
end
|
508
|
-
|
509
|
-
context 'when in #before block in singleton method with other object in #describe block in top level' do
|
510
|
-
let(:source) do
|
511
|
-
<<-END
|
512
|
-
describe 'foo' do
|
513
|
-
some_object = 'some object'
|
514
|
-
|
515
|
-
def some_object.before
|
516
|
-
yield
|
517
|
-
end
|
518
|
-
|
519
|
-
def some_object.some_method
|
520
|
-
before do
|
521
|
-
target
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
some_object.some_method
|
526
|
-
end
|
527
|
-
END
|
528
|
-
end
|
529
|
-
|
530
|
-
include_examples 'context inspection methods'
|
531
|
-
end
|
532
|
-
|
533
|
-
context 'when in a class in a block in #describe block' do
|
534
|
-
let(:source) do
|
535
|
-
<<-END
|
536
|
-
describe 'foo' do
|
537
|
-
it 'is an example' do
|
538
|
-
class Klass
|
539
|
-
target
|
540
|
-
end
|
541
|
-
end
|
542
|
-
end
|
543
|
-
END
|
544
|
-
end
|
545
|
-
|
546
|
-
include_examples 'context inspection methods'
|
547
|
-
end
|
548
|
-
|
549
|
-
context 'when in an instance method in a class in a block in #describe block' do
|
550
|
-
let(:source) do
|
551
|
-
<<-END
|
552
|
-
describe 'foo' do
|
553
|
-
it 'is an example' do
|
554
|
-
class Klass
|
555
|
-
def some_method
|
556
|
-
target
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
Klass.new.some_method
|
561
|
-
end
|
562
|
-
end
|
563
|
-
END
|
564
|
-
end
|
565
|
-
|
566
|
-
include_examples 'context inspection methods'
|
567
|
-
end
|
568
|
-
|
569
|
-
context 'when in #describe block in a module' do
|
570
|
-
let(:source) do
|
571
|
-
<<-END
|
572
|
-
module SomeModule
|
573
|
-
describe 'foo' do
|
574
|
-
target
|
575
|
-
end
|
576
|
-
end
|
577
|
-
END
|
578
|
-
end
|
579
|
-
|
580
|
-
include_examples 'context inspection methods'
|
581
|
-
end
|
582
|
-
|
583
|
-
context 'when in an instance method in #describe block in a module' do
|
584
|
-
let(:source) do
|
585
|
-
<<-END
|
586
|
-
module SomeModule
|
587
|
-
describe 'foo' do
|
588
|
-
def some_method
|
589
|
-
target
|
590
|
-
end
|
591
|
-
|
592
|
-
example { some_method }
|
593
|
-
end
|
594
|
-
end
|
595
|
-
END
|
596
|
-
end
|
597
|
-
|
598
|
-
include_examples 'context inspection methods'
|
599
|
-
end
|
600
|
-
|
601
|
-
context 'when in a block in #describe block in a module' do
|
602
|
-
let(:source) do
|
603
|
-
<<-END
|
604
|
-
module SomeModule
|
605
|
-
describe 'foo' do
|
606
|
-
it 'is an example' do
|
607
|
-
target
|
608
|
-
end
|
609
|
-
end
|
610
|
-
end
|
611
|
-
END
|
612
|
-
end
|
613
|
-
|
614
|
-
include_examples 'context inspection methods'
|
615
|
-
end
|
616
|
-
|
617
|
-
context 'when in an instance method in a module' do
|
618
|
-
let(:source) do
|
619
|
-
<<-END
|
620
|
-
module SomeModule
|
621
|
-
def some_method
|
622
|
-
target
|
623
|
-
end
|
624
|
-
end
|
625
|
-
|
626
|
-
describe 'test' do
|
627
|
-
include SomeModule
|
628
|
-
example { some_method }
|
629
|
-
end
|
630
|
-
END
|
631
|
-
end
|
632
|
-
|
633
|
-
# Instance methods of module can be used by `include SomeModule` in #describe block.
|
634
|
-
include_examples 'context inspection methods'
|
635
|
-
end
|
636
|
-
|
637
|
-
context 'when in an instance method in a class' do
|
638
|
-
let(:source) do
|
639
|
-
<<-END
|
640
|
-
class Klass
|
641
|
-
def some_method
|
642
|
-
target
|
643
|
-
end
|
644
|
-
end
|
645
|
-
|
646
|
-
describe 'test' do
|
647
|
-
example { Klass.new.some_method }
|
648
|
-
end
|
649
|
-
END
|
650
|
-
end
|
651
|
-
|
652
|
-
include_examples 'context inspection methods'
|
653
|
-
end
|
654
|
-
|
655
|
-
context 'when in RSpec.configure' do
|
656
|
-
let(:source) do
|
657
|
-
<<-END
|
658
|
-
RSpec.configure do |config|
|
659
|
-
target
|
660
|
-
end
|
661
|
-
END
|
662
|
-
end
|
663
|
-
|
664
|
-
include_examples 'context inspection methods'
|
665
|
-
end
|
666
|
-
|
667
|
-
context 'when in #before block in RSpec.configure' do
|
668
|
-
let(:source) do
|
669
|
-
<<-END
|
670
|
-
RSpec.configure do |config|
|
671
|
-
config.before do
|
672
|
-
target
|
673
|
-
end
|
674
|
-
end
|
675
|
-
|
676
|
-
describe('test') { example { } }
|
677
|
-
END
|
678
|
-
end
|
679
|
-
|
680
|
-
include_examples 'context inspection methods'
|
681
|
-
end
|
682
|
-
|
683
|
-
context 'when in a normal block in RSpec.configure' do
|
684
|
-
let(:source) do
|
685
|
-
<<-END
|
686
|
-
RSpec.configure do |config|
|
687
|
-
1.times do
|
688
|
-
target
|
689
|
-
end
|
690
|
-
end
|
691
|
-
END
|
692
|
-
end
|
693
|
-
|
694
|
-
include_examples 'context inspection methods'
|
695
|
-
end
|
696
|
-
|
697
|
-
context 'when in an instance method in RSpec.configure' do
|
698
|
-
let(:source) do
|
699
|
-
<<-END
|
700
|
-
RSpec.configure do |config|
|
701
|
-
def some_method
|
702
|
-
target
|
703
|
-
end
|
704
|
-
end
|
705
|
-
|
706
|
-
describe('test') { example { some_method } }
|
707
|
-
END
|
708
|
-
end
|
709
|
-
|
710
|
-
include_examples 'context inspection methods'
|
711
|
-
end
|
712
|
-
end
|
713
|
-
end
|