transpec 1.1.1 → 1.1.2
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/CHANGELOG.md +4 -0
- data/README.md +14 -2
- data/README.md.erb +14 -2
- data/lib/transpec/syntax/mixin/monkey_patch.rb +1 -1
- data/lib/transpec/syntax/operator_matcher.rb +1 -1
- data/lib/transpec/syntax/should.rb +1 -1
- data/lib/transpec/version.rb +1 -1
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +2 -2
- data/spec/transpec/syntax/operator_matcher_spec.rb +2 -2
- data/spec/transpec/syntax/should_spec.rb +36 -2
- data/transpec.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4b8ad9709db52ce5becc1fe21c78454138667a5
|
4
|
+
data.tar.gz: 91977cdc9490c4fd3878769d0308cc01f551a7ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1656fc0b87a530e09d986213f76cb3ec52efd78d7fc5106ddb4d555461f8699ad10f2bd23c4fe4b8ca49a3fe78bd926b2123231e95a9cefc6ce69bf9cc5ec6db
|
7
|
+
data.tar.gz: efa265154035cc620e19e4b7ce0e87345337c152f34f737a87c85820d96e02421002b5f596292ab9ceba1810292f8dfb3b53314168050719c69e195905eef2b3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
+
## v1.1.2
|
6
|
+
|
7
|
+
* Allow use of non monkey patch syntaxes in non example group contexts by including `RSpec::Matchers` ([#15](https://github.com/yujinakayama/transpec/issues/15))
|
8
|
+
|
5
9
|
## v1.1.1
|
6
10
|
|
7
11
|
* Fix failure of dynamic analysis when cwd was changed at exit of rspec
|
data/README.md
CHANGED
@@ -295,14 +295,26 @@ end
|
|
295
295
|
### Reason
|
296
296
|
|
297
297
|
* `should` is defined on `BasicObject` class, so you can use `should` everywhere.
|
298
|
-
* `expect` is defined on `RSpec::Matchers` module that is included by `RSpec::Core::ExampleGroup` class, so you can use `expect` only where `self` is an instance of `RSpec::Core::ExampleGroup` (i.e. in `it` blocks, `:each` hook blocks or included module methods)
|
298
|
+
* `expect` is defined on `RSpec::Matchers` module that is included by `RSpec::Core::ExampleGroup` class, so you can use `expect` only where `self` is an instance of `RSpec::Core::ExampleGroup` (i.e. in `it` blocks, `:each` hook blocks or included module methods) or other classes that include `RSpec::Matchers`.
|
299
299
|
|
300
300
|
With the above example, in the context of `1.should == 1`, the `self` is an instance of `MyAwesomeTestRunner`.
|
301
301
|
Transpec tracks contexts and skips conversion if the target syntax cannot be converted in a case like this.
|
302
302
|
|
303
303
|
### Solution
|
304
304
|
|
305
|
-
|
305
|
+
Include or extend `RSpec::Matchers` module to make `expect` available in the context:
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
class MyAwesomeTestRunner
|
309
|
+
include RSpec::Matchers
|
310
|
+
|
311
|
+
def run
|
312
|
+
1.should == 1
|
313
|
+
end
|
314
|
+
end
|
315
|
+
```
|
316
|
+
|
317
|
+
Then run `transpec` again.
|
306
318
|
|
307
319
|
## Supported Conversions
|
308
320
|
|
data/README.md.erb
CHANGED
@@ -291,14 +291,26 @@ end
|
|
291
291
|
### Reason
|
292
292
|
|
293
293
|
* `should` is defined on `BasicObject` class, so you can use `should` everywhere.
|
294
|
-
* `expect` is defined on `RSpec::Matchers` module that is included by `RSpec::Core::ExampleGroup` class, so you can use `expect` only where `self` is an instance of `RSpec::Core::ExampleGroup` (i.e. in `it` blocks, `:each` hook blocks or included module methods)
|
294
|
+
* `expect` is defined on `RSpec::Matchers` module that is included by `RSpec::Core::ExampleGroup` class, so you can use `expect` only where `self` is an instance of `RSpec::Core::ExampleGroup` (i.e. in `it` blocks, `:each` hook blocks or included module methods) or other classes that include `RSpec::Matchers`.
|
295
295
|
|
296
296
|
With the above example, in the context of `1.should == 1`, the `self` is an instance of `MyAwesomeTestRunner`.
|
297
297
|
Transpec tracks contexts and skips conversion if the target syntax cannot be converted in a case like this.
|
298
298
|
|
299
299
|
### Solution
|
300
300
|
|
301
|
-
|
301
|
+
Include or extend `RSpec::Matchers` module to make `expect` available in the context:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
class MyAwesomeTestRunner
|
305
|
+
include RSpec::Matchers
|
306
|
+
|
307
|
+
def run
|
308
|
+
1.should == 1
|
309
|
+
end
|
310
|
+
end
|
311
|
+
```
|
312
|
+
|
313
|
+
Then run `transpec` again.
|
302
314
|
|
303
315
|
## Supported Conversions
|
304
316
|
|
@@ -5,7 +5,7 @@ module Transpec
|
|
5
5
|
module Mixin
|
6
6
|
module MonkeyPatch
|
7
7
|
def register_request_of_syntax_availability_inspection(rewriter, key, methods)
|
8
|
-
code = "self.class.name.start_with?('RSpec::')"
|
8
|
+
code = "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') }"
|
9
9
|
|
10
10
|
methods.each do |method|
|
11
11
|
code << " && respond_to?(#{method.inspect})"
|
@@ -24,7 +24,7 @@ module Transpec
|
|
24
24
|
rewriter.register_request(arg_node, :arg_is_enumerable?, 'is_a?(Enumerable)')
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def convert_operator!(parenthesize_arg = true)
|
28
28
|
case method_name
|
29
29
|
when :==
|
30
30
|
convert_to_eq!(parenthesize_arg)
|
@@ -59,7 +59,7 @@ module Transpec
|
|
59
59
|
@current_syntax_type = :expect
|
60
60
|
register_record(negative_form)
|
61
61
|
|
62
|
-
operator_matcher.
|
62
|
+
operator_matcher.convert_operator!(parenthesize_matcher_arg) if operator_matcher
|
63
63
|
end
|
64
64
|
|
65
65
|
def operator_matcher
|
data/lib/transpec/version.rb
CHANGED
@@ -28,7 +28,7 @@ module Transpec
|
|
28
28
|
<<-END
|
29
29
|
describe 'example' do
|
30
30
|
it 'is foo' do
|
31
|
-
transpec_analysis((transpec_analysis((subject), self, { :should_source_location => [:object, "method(:should).source_location"] }, __FILE__, 79, 86).should be(foo)), self, { :expect_available? => [:context, "self.class.name.start_with?('RSpec::') && respond_to?(:expect)"] }, __FILE__, 79, 101)
|
31
|
+
transpec_analysis((transpec_analysis((subject), self, { :should_source_location => [:object, "method(:should).source_location"] }, __FILE__, 79, 86).should be(foo)), self, { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] }, __FILE__, 79, 101)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
END
|
@@ -57,7 +57,7 @@ module Transpec
|
|
57
57
|
<<-END
|
58
58
|
describe 'example' do
|
59
59
|
it 'matches to foo' do
|
60
|
-
transpec_analysis((transpec_analysis((subject), self, { :should_source_location => [:object, "method(:should).source_location"] }, __FILE__, 93, 100).should), self, { :expect_available? => [:context, "self.class.name.start_with?('RSpec::') && respond_to?(:expect)"] }, __FILE__, 93, 107) =~ transpec_analysis((<<-HEREDOC.gsub('foo', 'bar')
|
60
|
+
transpec_analysis((transpec_analysis((subject), self, { :should_source_location => [:object, "method(:should).source_location"] }, __FILE__, 93, 100).should), self, { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] }, __FILE__, 93, 107) =~ transpec_analysis((<<-HEREDOC.gsub('foo', 'bar')
|
61
61
|
foo
|
62
62
|
HEREDOC
|
63
63
|
), self, { :arg_is_enumerable? => [:object, "is_a?(Enumerable)"] }, __FILE__, 111, 188)
|
@@ -70,9 +70,9 @@ module Transpec
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe '#
|
73
|
+
describe '#convert_operator!' do
|
74
74
|
before do
|
75
|
-
matcher.
|
75
|
+
matcher.convert_operator!(parenthesize_arg)
|
76
76
|
end
|
77
77
|
|
78
78
|
let(:parenthesize_arg) { true }
|
@@ -189,8 +189,8 @@ module Transpec
|
|
189
189
|
END
|
190
190
|
end
|
191
191
|
|
192
|
-
it 'invokes OperatorMatcher#
|
193
|
-
should_object.operator_matcher.should_receive(:
|
192
|
+
it 'invokes OperatorMatcher#convert_operator!' do
|
193
|
+
should_object.operator_matcher.should_receive(:convert_operator!)
|
194
194
|
should_object.expectize!
|
195
195
|
end
|
196
196
|
|
@@ -226,6 +226,40 @@ module Transpec
|
|
226
226
|
record.converted_syntax.should == 'expect(obj).to'
|
227
227
|
end
|
228
228
|
|
229
|
+
context 'and #expect is available in the context by including RSpec::Matchers' do
|
230
|
+
let(:source) do
|
231
|
+
<<-END
|
232
|
+
describe 'example' do
|
233
|
+
class TestRunner
|
234
|
+
include RSpec::Matchers
|
235
|
+
|
236
|
+
def run
|
237
|
+
1.should == 1
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'is 1' do
|
242
|
+
TestRunner.new.run
|
243
|
+
end
|
244
|
+
end
|
245
|
+
END
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'with runtime information' do
|
249
|
+
include_context 'dynamic analysis objects'
|
250
|
+
|
251
|
+
it 'does not raise InvalidContextError' do
|
252
|
+
-> { should_object.expectize! }.should_not raise_error
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'without runtime information' do
|
257
|
+
it 'raises InvalidContextError' do
|
258
|
+
-> { should_object.expectize! }.should raise_error(InvalidContextError)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
229
263
|
context 'and #expect is not available in the context' do
|
230
264
|
context 'and the context is determinable statically' do
|
231
265
|
let(:source) do
|
data/transpec.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Transpec::Version.to_s
|
10
10
|
spec.authors = ['Yuji Nakayama']
|
11
11
|
spec.email = ['nkymyj@gmail.com']
|
12
|
-
spec.summary = 'RSpec syntax converter'
|
13
|
-
spec.description = 'Transpec
|
12
|
+
spec.summary = 'A RSpec syntax converter'
|
13
|
+
spec.description = 'Transpec converts your specs into latest RSpec syntax ' +
|
14
14
|
'with static and dynamic code analysis.'
|
15
15
|
spec.homepage = 'https://github.com/yujinakayama/transpec'
|
16
16
|
spec.license = 'MIT'
|
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.1.
|
4
|
+
version: 1.1.2
|
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-11-
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -164,8 +164,8 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.3'
|
167
|
-
description: Transpec
|
168
|
-
|
167
|
+
description: Transpec converts your specs into latest RSpec syntax with static and
|
168
|
+
dynamic code analysis.
|
169
169
|
email:
|
170
170
|
- nkymyj@gmail.com
|
171
171
|
executables:
|
@@ -281,7 +281,7 @@ rubyforge_project:
|
|
281
281
|
rubygems_version: 2.0.3
|
282
282
|
signing_key:
|
283
283
|
specification_version: 4
|
284
|
-
summary: RSpec syntax converter
|
284
|
+
summary: A RSpec syntax converter
|
285
285
|
test_files:
|
286
286
|
- spec/.rubocop.yml
|
287
287
|
- spec/spec_helper.rb
|