transpec 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +188 -90
- data/README.md.erb +190 -90
- data/lib/transpec/converter.rb +8 -13
- data/lib/transpec/dynamic_analyzer.rb +0 -1
- data/lib/transpec/dynamic_analyzer/rewriter.rb +6 -1
- data/lib/transpec/rspec_dsl.rb +15 -4
- data/lib/transpec/rspec_version.rb +6 -5
- data/lib/transpec/static_context_inspector.rb +25 -1
- data/lib/transpec/syntax.rb +7 -0
- data/lib/transpec/syntax/matcher_definition.rb +30 -0
- data/lib/transpec/syntax/mixin/send.rb +1 -1
- data/lib/transpec/util.rb +2 -4
- data/lib/transpec/version.rb +2 -2
- data/spec/transpec/converter_spec.rb +53 -14
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +24 -45
- data/spec/transpec/rspec_version_spec.rb +2 -2
- data/spec/transpec/static_context_inspector_spec.rb +99 -47
- data/spec/transpec/syntax/matcher_definition_spec.rb +59 -0
- data/tasks/readme.rake +19 -2
- data/transpec.gemspec +1 -1
- metadata +7 -4
@@ -35,7 +35,7 @@ module Transpec
|
|
35
35
|
]
|
36
36
|
end
|
37
37
|
|
38
|
-
[:
|
38
|
+
[:oneliner_is_expected_available?].each do |method|
|
39
39
|
include_examples 'feature availability', method, [
|
40
40
|
['2.14.0', false],
|
41
41
|
['2.99.0.beta1', false],
|
@@ -59,7 +59,7 @@ module Transpec
|
|
59
59
|
]
|
60
60
|
end
|
61
61
|
|
62
|
-
[:receive_message_chain_available?].each do |method|
|
62
|
+
[:receive_message_chain_available?, :non_should_matcher_protocol_available?].each do |method|
|
63
63
|
include_examples 'feature availability', method, [
|
64
64
|
['2.14.0', false],
|
65
65
|
['2.99.0.beta1', false],
|
@@ -45,54 +45,106 @@ module Transpec
|
|
45
45
|
end
|
46
46
|
|
47
47
|
1.times do
|
48
|
-
|
49
|
-
end
|
48
|
+
in_block
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
feature 'Capybara DSL' do
|
53
|
+
background do
|
54
|
+
in_background
|
55
|
+
end
|
56
|
+
|
57
|
+
given(:foo) do
|
58
|
+
in_given
|
59
|
+
end
|
60
|
+
|
61
|
+
scenario 'some page shows something' do
|
62
|
+
in_scenario
|
63
|
+
end
|
64
|
+
end
|
65
|
+
END
|
66
|
+
end
|
67
|
+
|
68
|
+
[
|
69
|
+
[
|
70
|
+
'send nil :top_level',
|
71
|
+
'in top level',
|
72
|
+
[]
|
73
|
+
], [
|
74
|
+
'send nil :in_before',
|
75
|
+
'in before block in RSpec.configure',
|
76
|
+
[:rspec_configure, :each_before_after]
|
77
|
+
], [
|
78
|
+
'module',
|
79
|
+
'at module definition in top level',
|
80
|
+
[]
|
81
|
+
], [
|
82
|
+
'const nil :SomeModule',
|
83
|
+
'at constant of module definition',
|
84
|
+
[]
|
85
|
+
], [
|
86
|
+
'send nil :in_module',
|
87
|
+
'in module',
|
88
|
+
[:module]
|
89
|
+
], [
|
90
|
+
'send nil :describe',
|
91
|
+
'at #describe in module',
|
92
|
+
[:module]
|
93
|
+
], [
|
94
|
+
'def :some_method',
|
95
|
+
'at method definition in #describe in module',
|
96
|
+
[:module, :example_group]
|
97
|
+
], [
|
98
|
+
'arg :some_arg',
|
99
|
+
'at method argument in #describe in module',
|
100
|
+
[:module, :example_group, :def]
|
101
|
+
], [
|
102
|
+
'send nil :do_something',
|
103
|
+
'in method in #describe in module',
|
104
|
+
[:module, :example_group, :def]
|
105
|
+
], [
|
106
|
+
'send nil :it',
|
107
|
+
'at #it in #describe in module',
|
108
|
+
[:module, :example_group]
|
109
|
+
], [
|
110
|
+
'str "is 1"',
|
111
|
+
"at #it's description in #describe in module",
|
112
|
+
[:module, :example_group]
|
113
|
+
], [
|
114
|
+
'send nil :in_example',
|
115
|
+
'#it in #describe in module',
|
116
|
+
[:module, :example_group, :example]
|
117
|
+
], [
|
118
|
+
'send nil :in_block',
|
119
|
+
'in normal block in #describe in module',
|
120
|
+
[:module]
|
121
|
+
], [
|
122
|
+
'send nil :in_background',
|
123
|
+
'in #background block in #feature',
|
124
|
+
[:example_group, :each_before_after]
|
125
|
+
], [
|
126
|
+
'send nil :in_given',
|
127
|
+
'in #given block in #feature',
|
128
|
+
[:example_group, :helper]
|
129
|
+
], [
|
130
|
+
'send nil :in_scenario',
|
131
|
+
'in #scenario block in #feature',
|
132
|
+
[:example_group, :example]
|
133
|
+
]
|
134
|
+
].each do |target_node_id, description, expected_scopes|
|
135
|
+
context "when #{description}" do
|
136
|
+
let(:target_node) do
|
137
|
+
ast.each_node.find do |node|
|
138
|
+
node_id(node) == target_node_id
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "returns #{expected_scopes.inspect}" do
|
143
|
+
fail 'Target node is not found!' unless target_node
|
144
|
+
|
145
|
+
context_inspector = StaticContextInspector.new(target_node)
|
146
|
+
context_inspector.scopes.should == expected_scopes
|
50
147
|
end
|
51
|
-
END
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'returns scope stack' do
|
55
|
-
ast.each_node do |node|
|
56
|
-
expected_scopes = begin
|
57
|
-
case node_id(node)
|
58
|
-
when 'send nil :top_level'
|
59
|
-
[]
|
60
|
-
when 'send nil :in_before'
|
61
|
-
[:rspec_configure, :each_before_after]
|
62
|
-
when 'module'
|
63
|
-
[]
|
64
|
-
when 'const nil :SomeModule'
|
65
|
-
# [:module] # TODO
|
66
|
-
when 'send nil :in_module'
|
67
|
-
[:module]
|
68
|
-
when 'send nil :describe'
|
69
|
-
# [:module] # TODO
|
70
|
-
when 'def :some_method'
|
71
|
-
[:module, :example_group]
|
72
|
-
when 'arg :some_arg'
|
73
|
-
# [:module, :example_group] # TODO
|
74
|
-
when 'send nil :do_something'
|
75
|
-
[:module, :example_group, :def]
|
76
|
-
when 'send nil :it'
|
77
|
-
# [:module, :example_group] # TODO
|
78
|
-
when 'str "is 1"'
|
79
|
-
# [:module, :example_group] # TODO
|
80
|
-
when 'send nil :in_example'
|
81
|
-
[:module, :example_group, :example]
|
82
|
-
when 'send nil :in_normal_block'
|
83
|
-
[:module]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# TODO: Some scope nodes have special child nodes
|
88
|
-
# such as their arguments or their subject.
|
89
|
-
# But from scope point of view, the child nodes are not in the parent's scope,
|
90
|
-
# they should be in the next outer scope.
|
91
|
-
|
92
|
-
next unless expected_scopes
|
93
|
-
|
94
|
-
context_inspector = StaticContextInspector.new(node)
|
95
|
-
context_inspector.scopes.should == expected_scopes
|
96
148
|
end
|
97
149
|
end
|
98
150
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'transpec/syntax/matcher_definition'
|
5
|
+
|
6
|
+
module Transpec
|
7
|
+
class Syntax
|
8
|
+
describe MatcherDefinition do
|
9
|
+
include_context 'parsed objects'
|
10
|
+
include_context 'syntax object', MatcherDefinition, :matcher_definition
|
11
|
+
|
12
|
+
let(:record) { matcher_definition.report.records.last }
|
13
|
+
|
14
|
+
describe '#convert_deprecated_method!' do
|
15
|
+
before do
|
16
|
+
matcher_definition.convert_deprecated_method!
|
17
|
+
end
|
18
|
+
|
19
|
+
[
|
20
|
+
[:match_for_should, :match],
|
21
|
+
[:match_for_should_not, :match_when_negated],
|
22
|
+
[:failure_message_for_should, :failure_message],
|
23
|
+
[:failure_message_for_should_not, :failure_message_when_negated]
|
24
|
+
].each do |target_method, converted_method|
|
25
|
+
context "when it is `#{target_method} { }` form" do
|
26
|
+
let(:source) do
|
27
|
+
<<-END
|
28
|
+
RSpec::Matchers.define :be_awesome do |expected|
|
29
|
+
#{target_method} do |actual|
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
END
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:expected_source) do
|
37
|
+
<<-END
|
38
|
+
RSpec::Matchers.define :be_awesome do |expected|
|
39
|
+
#{converted_method} do |actual|
|
40
|
+
true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
END
|
44
|
+
end
|
45
|
+
|
46
|
+
it "converts into `#{converted_method} { }` form" do
|
47
|
+
rewritten_source.should == expected_source
|
48
|
+
end
|
49
|
+
|
50
|
+
it "adds record `#{target_method} { }` -> `#{converted_method} { }`" do
|
51
|
+
record.original_syntax.should == "#{target_method} { }"
|
52
|
+
record.converted_syntax.should == "#{converted_method} { }"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/tasks/readme.rake
CHANGED
@@ -2,10 +2,27 @@
|
|
2
2
|
|
3
3
|
desc 'Generate README.md'
|
4
4
|
task :readme do
|
5
|
+
File.write('README.md', generate_readme)
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :readme do
|
9
|
+
task :check do
|
10
|
+
unless File.read('README.md') == generate_readme
|
11
|
+
fail <<-END.gsub(/^\s+\|/, '').chomp
|
12
|
+
|README.md and README.md.erb are out of sync!
|
13
|
+
|If you need to modify the content of README.md:
|
14
|
+
| * Edit README.md.erb.
|
15
|
+
| * Run `bundle exec rake readme`.
|
16
|
+
| * Commit both files.
|
17
|
+
END
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_readme
|
5
23
|
require 'erb'
|
6
24
|
require 'transpec/cli'
|
7
25
|
|
8
26
|
erb = ERB.new(File.read('README.md.erb'), nil, '-')
|
9
|
-
|
10
|
-
File.write('README.md', content)
|
27
|
+
erb.result(binding)
|
11
28
|
end
|
data/transpec.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_runtime_dependency 'parser', '~> 2.
|
23
|
+
spec.add_runtime_dependency 'parser', '~> 2.1'
|
24
24
|
spec.add_runtime_dependency 'bundler', '~> 1.3'
|
25
25
|
spec.add_runtime_dependency 'rainbow', '~> 1.1'
|
26
26
|
spec.add_runtime_dependency 'json', '~> 1.8'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transpec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- lib/transpec/syntax/expect.rb
|
243
243
|
- lib/transpec/syntax/have.rb
|
244
244
|
- lib/transpec/syntax/its.rb
|
245
|
+
- lib/transpec/syntax/matcher_definition.rb
|
245
246
|
- lib/transpec/syntax/method_stub.rb
|
246
247
|
- lib/transpec/syntax/mixin/allow_no_message.rb
|
247
248
|
- lib/transpec/syntax/mixin/any_instance.rb
|
@@ -285,6 +286,7 @@ files:
|
|
285
286
|
- spec/transpec/syntax/expect_spec.rb
|
286
287
|
- spec/transpec/syntax/have_spec.rb
|
287
288
|
- spec/transpec/syntax/its_spec.rb
|
289
|
+
- spec/transpec/syntax/matcher_definition_spec.rb
|
288
290
|
- spec/transpec/syntax/method_stub_spec.rb
|
289
291
|
- spec/transpec/syntax/oneliner_should_spec.rb
|
290
292
|
- spec/transpec/syntax/operator_matcher_spec.rb
|
@@ -353,6 +355,7 @@ test_files:
|
|
353
355
|
- spec/transpec/syntax/expect_spec.rb
|
354
356
|
- spec/transpec/syntax/have_spec.rb
|
355
357
|
- spec/transpec/syntax/its_spec.rb
|
358
|
+
- spec/transpec/syntax/matcher_definition_spec.rb
|
356
359
|
- spec/transpec/syntax/method_stub_spec.rb
|
357
360
|
- spec/transpec/syntax/oneliner_should_spec.rb
|
358
361
|
- spec/transpec/syntax/operator_matcher_spec.rb
|