transpec 1.9.1 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c34e8b6406b750b87a6af37fd7ed8e1df46a235
4
- data.tar.gz: 6d778d31bc2c9518fda218793f8a740268ab3dc7
3
+ metadata.gz: a34ff8e04af60263124c8b388b44b5784ceba70f
4
+ data.tar.gz: a00f6ffbf41aab7e020aedd0487837279557e039
5
5
  SHA512:
6
- metadata.gz: a9e4b610441d631390420e67e391e759b1180e3260abe01ff78deb4fe3cefc57838f9d33da1a1cd5560d5e411a9ddd65f06c8c2fd287dce6a4203cacd737d5eb
7
- data.tar.gz: 1ba96f0b28b40c05dd29257caead516bedfb4e4fac7fc4d51a56445f1e6734514385d1a27bd0610975d8ba4e513920b5d4e0c40807f6dc4c69c6d158bfa26bab
6
+ metadata.gz: 8258e12de1f9553ac0a89f32e05c061c529dbda6d7e7877b46356359f7bdd6899ee2eebe527bbcce7b4f72a8031b91ace460b06fc8662215f711930277f05401
7
+ data.tar.gz: aeafa19c49cf9fa8dfe031c13118681dff4351fa56a1279117f878af27a033ff8620b2ec316ca49cf03caee2396ce326c719d9275f156927558139278bb6f700
@@ -54,4 +54,4 @@ BracesAroundHashParameters:
54
54
 
55
55
  # TODO: Shorten to 100.
56
56
  ClassLength:
57
- Max: 170
57
+ Max: 173
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v1.9.2
6
+
7
+ * Fix a bug where `expect(method_returns_collection :some_arg).to have(2).items` was converted to `expect(method_returns_collection :some_arg.size).to eq(2)` ([#43](https://github.com/yujinakayama/transpec/issues/43))
8
+ * Fix false positive conversion of `raise_error` with `with_message` ([#41](https://github.com/yujinakayama/transpec/issues/41))
9
+
5
10
  ## v1.9.1
6
11
 
7
12
  * Fix crash on `expect(obj).to non_matcher_object` in dynamic analysis ([#39](https://github.com/yujinakayama/transpec/issues/39))
data/README.md CHANGED
@@ -404,7 +404,7 @@ The one-liner (implicit receiver) `should`:
404
404
  * Is provided by `rspec-core` gem.
405
405
  * Is _not_ deprecated in RSpec 3.
406
406
  * Does _not_ have the issue with delegate/proxy objects.
407
- * There's the alternative syntax [`is_expected.to`](#one-liner-expectations) since RSpec 2.99.beta2 (not yet released).
407
+ * There's the alternative syntax [`is_expected.to`](#one-liner-expectations) since RSpec 2.99.beta2.
408
408
 
409
409
  ## Supported Conversions
410
410
 
@@ -453,7 +453,7 @@ expect(obj).to_not matcher # with `--negative-form to_not`
453
453
 
454
454
  ### One-liner expectations
455
455
 
456
- **This conversion is available only if your project's RSpec is `2.99.0.beta2` (not yet released) or later.**
456
+ **This conversion is available only if your project's RSpec is `2.99.0.beta2` or later.**
457
457
 
458
458
  Targets:
459
459
 
@@ -802,7 +802,7 @@ Will be converted to:
802
802
  allow(obj).to receive(:message)
803
803
 
804
804
  # Conversion from `stub_chain` to `receive_message_chain` is available
805
- # only if the target project's RSpec is 3.0.0.beta2 (not yet released) or later
805
+ # only if the target project's RSpec is 3.0.0.beta2 or later
806
806
  allow(obj).to receive_message_chain(:foo, :bar, :baz)
807
807
 
808
808
  allow_any_instance_of(Klass).to receive(:message)
@@ -1079,7 +1079,7 @@ Here's an excerpt from [the warning](https://github.com/rspec/rspec-core/blob/7d
1079
1079
 
1080
1080
  ### Custom matcher DSL
1081
1081
 
1082
- **This conversion is available only if your project's RSpec is `3.0.0.beta2` (not yet released) or later.**
1082
+ **This conversion is available only if your project's RSpec is `3.0.0.beta2` or later.**
1083
1083
 
1084
1084
  Targets:
1085
1085
 
@@ -401,20 +401,13 @@ The one-liner (implicit receiver) `should`:
401
401
  * Is provided by `rspec-core` gem.
402
402
  * Is _not_ deprecated in RSpec 3.
403
403
  * Does _not_ have the issue with delegate/proxy objects.
404
- * There's the alternative syntax [`is_expected.to`](#one-liner-expectations) since RSpec 2.99.beta2 (not yet released).
404
+ * There's the alternative syntax [`is_expected.to`](#one-liner-expectations) since RSpec 2.99.beta2.
405
405
 
406
406
  ## Supported Conversions
407
407
 
408
408
  <%=
409
-
410
- sections = readme.each_line.slice_before(/^## /)
411
-
412
- supported_conversions_section = sections.find do |section|
413
- section.first.include?('Supported Conversions')
414
- end
415
-
409
+ supported_conversions_section = select_sections(readme, 2, 'Supported Conversions').first
416
410
  table_of_contents(supported_conversions_section, 3)
417
-
418
411
  %>
419
412
 
420
413
  ### Standard expectations
@@ -440,7 +433,7 @@ expect(obj).to_not matcher # with `--negative-form to_not`
440
433
 
441
434
  ### One-liner expectations
442
435
 
443
- **This conversion is available only if your project's RSpec is `<%= Transpec::RSpecVersion.oneliner_is_expected_available_version %>` (not yet released) or later.**
436
+ **This conversion is available only if your project's RSpec is `<%= Transpec::RSpecVersion.oneliner_is_expected_available_version %>` or later.**
444
437
 
445
438
  Targets:
446
439
 
@@ -773,7 +766,7 @@ Will be converted to:
773
766
  allow(obj).to receive(:message)
774
767
 
775
768
  # Conversion from `stub_chain` to `receive_message_chain` is available
776
- # only if the target project's RSpec is <%= Transpec::RSpecVersion.receive_message_chain_available_version %> (not yet released) or later
769
+ # only if the target project's RSpec is <%= Transpec::RSpecVersion.receive_message_chain_available_version %> or later
777
770
  allow(obj).to receive_message_chain(:foo, :bar, :baz)
778
771
 
779
772
  allow_any_instance_of(Klass).to receive(:message)
@@ -1031,7 +1024,7 @@ Here's an excerpt from [the warning](https://github.com/rspec/rspec-core/blob/7d
1031
1024
 
1032
1025
  ### Custom matcher DSL
1033
1026
 
1034
- **This conversion is available only if your project's RSpec is `<%= Transpec::RSpecVersion.non_should_matcher_protocol_available_version %>` (not yet released) or later.**
1027
+ **This conversion is available only if your project's RSpec is `<%= Transpec::RSpecVersion.non_should_matcher_protocol_available_version %>` or later.**
1035
1028
 
1036
1029
  Targets:
1037
1030
 
@@ -55,6 +55,7 @@ module Transpec
55
55
  end
56
56
 
57
57
  process_have(should.have_matcher)
58
+ process_raise_error(should.raise_error_matcher)
58
59
  end
59
60
 
60
61
  def process_oneliner_should(oneliner_should)
@@ -76,10 +77,13 @@ module Transpec
76
77
  elsif @configuration.convert_oneliner? && @rspec_version.oneliner_is_expected_available?
77
78
  oneliner_should.expectize!(negative_form, parenthesize)
78
79
  end
80
+
81
+ process_raise_error(oneliner_should.raise_error_matcher)
79
82
  end
80
83
 
81
84
  def process_expect(expect)
82
85
  process_have(expect.have_matcher)
86
+ process_raise_error(expect.raise_error_matcher)
83
87
  process_messaging_host(expect.receive_matcher)
84
88
  end
85
89
 
@@ -144,6 +148,7 @@ module Transpec
144
148
  end
145
149
 
146
150
  def process_raise_error(raise_error)
151
+ return unless raise_error
147
152
  if @configuration.convert_deprecated_method?
148
153
  raise_error.remove_error_specification_with_negative_expectation!
149
154
  end
@@ -2,12 +2,16 @@
2
2
 
3
3
  require 'transpec/syntax'
4
4
  require 'transpec/syntax/mixin/expect_base'
5
- require 'transpec/syntax/mixin/have_matcher_owner'
5
+ require 'transpec/syntax/have'
6
+ require 'transpec/syntax/raise_error'
6
7
 
7
8
  module Transpec
8
9
  class Syntax
9
10
  class Expect < Syntax
10
- include Mixin::ExpectBase, Mixin::HaveMatcherOwner
11
+ include Mixin::ExpectBase
12
+
13
+ add_matcher Have
14
+ add_matcher RaiseError
11
15
 
12
16
  def self.target_method?(receiver_node, method_name)
13
17
  receiver_node.nil? && [:expect, :expect_any_instance_of].include?(method_name)
@@ -22,8 +22,6 @@ module Transpec
22
22
  # for String (String responds to #size).
23
23
  QUERY_METHOD_PRIORITIES = [:size, :count, :length].freeze
24
24
 
25
- attr_reader :expectation
26
-
27
25
  def self.target_method?(receiver_node, method_name)
28
26
  receiver_node.nil? &&
29
27
  [:have, :have_exactly, :have_at_least, :have_at_most].include?(method_name)
@@ -95,9 +93,9 @@ module Transpec
95
93
  QUERY_METHOD_PRIORITIES.first
96
94
  end
97
95
 
98
- def replacement_subject_source(original_subject_source = nil)
99
- original_subject_source ||= expectation.subject_range.source
100
- source_builder.replacement_subject_source(original_subject_source)
96
+ def replacement_subject_source(base_subject = nil)
97
+ base_subject ||= expectation.subject_node
98
+ source_builder.replacement_subject_source(base_subject)
101
99
  end
102
100
 
103
101
  def size_source
@@ -13,8 +13,13 @@ module Transpec
13
13
  @size_source = size_source
14
14
  end
15
15
 
16
- def replacement_subject_source(original_subject_source)
17
- source = original_subject_source
16
+ def replacement_subject_source(base_subject)
17
+ source = case base_subject
18
+ when String then base_subject
19
+ when AST::Node then base_subject_source(base_subject)
20
+ else fail "Invalid base subject #{base_subject}"
21
+ end
22
+
18
23
  if have.subject_is_owner_of_collection?
19
24
  if have.collection_accessor_is_private?
20
25
  source << ".send(#{have.collection_accessor.inspect}"
@@ -26,9 +31,26 @@ module Transpec
26
31
  source << ".#{have.collection_accessor}#{collection_accessor_args_parentheses_source}"
27
32
  end
28
33
  end
34
+
29
35
  source << ".#{have.query_method}"
30
36
  end
31
37
 
38
+ def base_subject_source(node)
39
+ if node.send_type? && (arg_node = node.children[2])
40
+ left_of_arg_source = node.loc.selector.end.join(arg_node.loc.expression.begin).source
41
+
42
+ if left_of_arg_source.match(/\A\s*\Z/)
43
+ source = node.loc.expression.begin.join(node.loc.selector.end).source
44
+ source << '('
45
+ source << arg_node.loc.expression.begin.join(node.loc.expression.end).source
46
+ source << ')'
47
+ return source
48
+ end
49
+ end
50
+
51
+ node.loc.expression.source
52
+ end
53
+
32
54
  def replacement_matcher_source(parenthesize_arg = true)
33
55
  case have.expectation.current_syntax_type
34
56
  when :should
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_support/concern'
4
4
  require 'transpec/syntax/mixin/send'
5
+ require 'transpec/syntax/mixin/matcher_owner'
5
6
  require 'transpec/syntax/receive'
6
7
  require 'transpec/util'
7
8
 
@@ -10,17 +11,10 @@ module Transpec
10
11
  module Mixin
11
12
  module ExpectBase
12
13
  extend ActiveSupport::Concern
13
- include Send
14
+ include Send, MatcherOwner
14
15
 
15
16
  included do
16
- define_dynamic_analysis_request do |rewriter|
17
- if Receive.dynamic_analysis_target_node?(matcher_node)
18
- create_receive_matcher.register_request_for_dynamic_analysis(rewriter)
19
- end
20
- end
21
-
22
- alias_method :subject_node, :arg_node
23
- alias_method :to_node, :parent_node
17
+ add_matcher Receive
24
18
  end
25
19
 
26
20
  def current_syntax_type
@@ -36,6 +30,18 @@ module Transpec
36
30
  to_method_name == :to
37
31
  end
38
32
 
33
+ def subject_node
34
+ arg_node || parent_node
35
+ end
36
+
37
+ def to_node
38
+ if parent_node.block_type? && parent_node.children.first.equal?(node)
39
+ parent_node.parent_node
40
+ else
41
+ parent_node
42
+ end
43
+ end
44
+
39
45
  def matcher_node
40
46
  to_arg_node = to_node.children[2]
41
47
  Util.each_forward_chained_node(to_arg_node, :include_origin)
@@ -49,22 +55,6 @@ module Transpec
49
55
  def subject_range
50
56
  subject_node.loc.expression
51
57
  end
52
-
53
- def receive_matcher
54
- return @receive_matcher if instance_variable_defined?(:@receive_matcher)
55
-
56
- @receive_matcher ||= if Receive.conversion_target_node?(matcher_node, @runtime_data)
57
- create_receive_matcher
58
- else
59
- nil
60
- end
61
- end
62
-
63
- private
64
-
65
- def create_receive_matcher
66
- Receive.new(matcher_node, self, @source_rewriter, @runtime_data, @report)
67
- end
68
58
  end
69
59
  end
70
60
  end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ require 'active_support/concern'
4
+
5
+ module Transpec
6
+ class Syntax
7
+ module Mixin
8
+ module MatcherOwner
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+ def add_matcher(matcher_class) # rubocop:disable MethodLength
13
+ matcher_accessor_name = "#{matcher_class.snake_case_name}_matcher"
14
+ matcher_ivar_name = "@#{matcher_accessor_name}"
15
+ matcher_creator_name = "create_#{matcher_class.snake_case_name}"
16
+
17
+ define_dynamic_analysis_request do |rewriter|
18
+ if matcher_class.dynamic_analysis_target_node?(matcher_node)
19
+ send(matcher_creator_name).register_request_for_dynamic_analysis(rewriter)
20
+ end
21
+ end
22
+
23
+ define_method(matcher_accessor_name) do
24
+ if instance_variable_defined?(matcher_ivar_name)
25
+ return instance_variable_get(matcher_ivar_name)
26
+ end
27
+
28
+ if matcher_class.conversion_target_node?(matcher_node, @runtime_data)
29
+ instance_variable_set(matcher_ivar_name, send(matcher_creator_name))
30
+ else
31
+ instance_variable_set(matcher_ivar_name, nil)
32
+ end
33
+ end
34
+
35
+ define_method(matcher_creator_name) do
36
+ matcher_class.new(matcher_node, self, @source_rewriter, @runtime_data, @report)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -8,6 +8,10 @@ module Transpec
8
8
  module OwnedMatcher
9
9
  extend ActiveSupport::Concern
10
10
 
11
+ included do
12
+ attr_reader :expectation
13
+ end
14
+
11
15
  module ClassMethods
12
16
  def standalone?
13
17
  false
@@ -2,8 +2,10 @@
2
2
 
3
3
  require 'active_support/concern'
4
4
  require 'transpec/syntax/mixin/send'
5
- require 'transpec/syntax/mixin/have_matcher_owner'
6
- require 'transpec/syntax/operator_matcher'
5
+ require 'transpec/syntax/mixin/matcher_owner'
6
+ require 'transpec/syntax/have'
7
+ require 'transpec/syntax/operator'
8
+ require 'transpec/syntax/raise_error'
7
9
  require 'transpec/util'
8
10
 
9
11
  module Transpec
@@ -11,14 +13,12 @@ module Transpec
11
13
  module Mixin
12
14
  module ShouldBase
13
15
  extend ActiveSupport::Concern
14
- include Send, HaveMatcherOwner
16
+ include Send, MatcherOwner
15
17
 
16
18
  included do
17
- define_dynamic_analysis_request do |rewriter|
18
- if OperatorMatcher.dynamic_analysis_target_node?(matcher_node)
19
- create_operator_matcher.register_request_for_dynamic_analysis(rewriter)
20
- end
21
- end
19
+ add_matcher Have
20
+ add_matcher Operator
21
+ add_matcher RaiseError
22
22
  end
23
23
 
24
24
  def positive?
@@ -41,24 +41,6 @@ module Transpec
41
41
  selector_range.join(expression_range.end)
42
42
  end
43
43
  end
44
-
45
- def operator_matcher
46
- return @operator_matcher if instance_variable_defined?(:@operator_matcher)
47
-
48
- @operator_matcher ||= begin
49
- if OperatorMatcher.conversion_target_node?(matcher_node, @runtime_data)
50
- create_operator_matcher
51
- else
52
- nil
53
- end
54
- end
55
- end
56
-
57
- private
58
-
59
- def create_operator_matcher
60
- OperatorMatcher.new(matcher_node, @source_rewriter, @runtime_data, @report)
61
- end
62
44
  end
63
45
  end
64
46
  end
@@ -2,14 +2,15 @@
2
2
 
3
3
  require 'transpec/syntax'
4
4
  require 'transpec/syntax/mixin/send'
5
+ require 'transpec/syntax/mixin/owned_matcher'
5
6
  require 'transpec/util'
6
7
  require 'ast'
7
8
 
8
9
  module Transpec
9
10
  class Syntax
10
- class OperatorMatcher < Syntax
11
+ class Operator < Syntax
11
12
  extend ::AST::Sexp
12
- include Mixin::Send, Util
13
+ include Mixin::Send, Mixin::OwnedMatcher, Util
13
14
 
14
15
  OPERATORS = [:==, :===, :<, :<=, :>, :>=, :=~].freeze
15
16
  BE_NODE = s(:send, nil, :be)
@@ -32,14 +33,14 @@ module Transpec
32
33
  end
33
34
  end
34
35
 
35
- def initialize(node, source_rewriter = nil, runtime_data = nil, report = nil)
36
+ def initialize(node, expectation, source_rewriter = nil, runtime_data = nil, report = nil)
36
37
  operator_node = if node == BE_NODE
37
38
  node.parent_node
38
39
  else
39
40
  node
40
41
  end
41
42
 
42
- super(operator_node, source_rewriter, runtime_data, report)
43
+ super(operator_node, expectation, source_rewriter, runtime_data, report)
43
44
  end
44
45
 
45
46
  def convert_operator!(parenthesize_arg = true)
@@ -2,18 +2,19 @@
2
2
 
3
3
  require 'transpec/syntax'
4
4
  require 'transpec/syntax/mixin/send'
5
+ require 'transpec/syntax/mixin/owned_matcher'
5
6
 
6
7
  module Transpec
7
8
  class Syntax
8
9
  class RaiseError < Syntax
9
- include Mixin::Send
10
+ include Mixin::Send, Mixin::OwnedMatcher
10
11
 
11
12
  def self.target_method?(receiver_node, method_name)
12
13
  receiver_node.nil? && method_name == :raise_error
13
14
  end
14
15
 
15
16
  def remove_error_specification_with_negative_expectation!
16
- return if positive?
17
+ return if expectation.positive?
17
18
 
18
19
  _receiver_node, _method_name, *arg_nodes = *node
19
20
  return if arg_nodes.empty?
@@ -23,16 +24,6 @@ module Transpec
23
24
  register_record
24
25
  end
25
26
 
26
- def positive?
27
- @node.each_ancestor_node do |ancestor_node|
28
- next unless ancestor_node.send_type?
29
- expectation_method_name = ancestor_node.children[1]
30
- return [:should, :to].include?(expectation_method_name)
31
- end
32
-
33
- false
34
- end
35
-
36
27
  private
37
28
 
38
29
  def register_record
@@ -10,8 +10,6 @@ module Transpec
10
10
  class Receive < Syntax
11
11
  include Mixin::Send, Mixin::OwnedMatcher, Mixin::MessagingHost
12
12
 
13
- attr_reader :expectation
14
-
15
13
  def self.target_method?(receiver_node, method_name)
16
14
  receiver_node.nil? && method_name == :receive
17
15
  end
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 1
7
7
  MINOR = 9
8
- PATCH = 1
8
+ PATCH = 2
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -121,7 +121,8 @@ module Transpec
121
121
  end
122
122
 
123
123
  describe '#process_should' do
124
- let(:should_object) { double('should_object').as_null_object }
124
+ let(:should_object) { double('should_object', raise_error_matcher: raise_error_object).as_null_object }
125
+ let(:raise_error_object) { double('raise_error_object').as_null_object }
125
126
 
126
127
  context 'when Configuration#convert_should? is true' do
127
128
  before { configuration.convert_should = true }
@@ -212,10 +213,16 @@ module Transpec
212
213
  converter.process_should(should_object)
213
214
  end
214
215
  end
216
+
217
+ it 'invokes #process_raise_error with its #raise_error_matcher' do
218
+ converter.should_receive(:process_raise_error).with(raise_error_object)
219
+ converter.process_should(should_object)
220
+ end
215
221
  end
216
222
 
217
223
  describe '#process_oneliner_should' do
218
- let(:should_object) { double('oneliner_should_object').as_null_object }
224
+ let(:should_object) { double('oneliner_should_object', raise_error_matcher: raise_error_object).as_null_object }
225
+ let(:raise_error_object) { double('raise_error_object').as_null_object }
219
226
 
220
227
  shared_examples 'does nothing' do
221
228
  it 'does nothing' do
@@ -363,11 +370,22 @@ module Transpec
363
370
  end
364
371
  end
365
372
  end
373
+
374
+ it 'invokes #process_raise_error with its #raise_error_matcher' do
375
+ converter.should_receive(:process_raise_error).with(raise_error_object)
376
+ converter.process_oneliner_should(should_object)
377
+ end
366
378
  end
367
379
 
368
380
  describe '#process_expect' do
369
- let(:expect_object) { double('expect_object', receive_matcher: receive_object).as_null_object }
381
+ let(:expect_object) do
382
+ double('expect_object',
383
+ receive_matcher: receive_object,
384
+ raise_error_matcher: raise_error_object
385
+ ).as_null_object
386
+ end
370
387
  let(:receive_object) { double('receive_object').as_null_object }
388
+ let(:raise_error_object) { double('raise_error_object').as_null_object }
371
389
 
372
390
  context 'when Configuration#convert_have_items? is true' do
373
391
  before { configuration.convert_have_items = true }
@@ -409,6 +427,11 @@ module Transpec
409
427
  converter.should_receive(:process_any_instance_block).with(receive_object)
410
428
  converter.process_expect(expect_object)
411
429
  end
430
+
431
+ it 'invokes #process_raise_error with its #raise_error_matcher' do
432
+ converter.should_receive(:process_raise_error).with(raise_error_object)
433
+ converter.process_expect(expect_object)
434
+ end
412
435
  end
413
436
 
414
437
  describe '#process_allow' do
@@ -10,19 +10,73 @@ module Transpec
10
10
  include_context 'syntax object', Expect, :expect_object
11
11
 
12
12
  describe '#subject_node' do
13
- let(:source) do
14
- <<-END
15
- describe 'example' do
16
- it 'is empty' do
17
- expect(subject).to be_empty
13
+ context 'when the subject is a normal argument' do
14
+ let(:source) do
15
+ <<-END
16
+ describe 'example' do
17
+ it 'is empty' do
18
+ expect(subject).to be_empty
19
+ end
18
20
  end
19
- end
20
- END
21
+ END
22
+ end
23
+
24
+ it 'returns the subject node' do
25
+ method_name = expect_object.subject_node.children[1]
26
+ method_name.should == :subject
27
+ end
21
28
  end
22
29
 
23
- it 'returns subject node' do
24
- method_name = expect_object.subject_node.children[1]
25
- method_name.should == :subject
30
+ context 'when the subject is a block' do
31
+ let(:source) do
32
+ <<-END
33
+ describe 'example' do
34
+ it 'raises error' do
35
+ expect { do_something }.to raise_error
36
+ end
37
+ end
38
+ END
39
+ end
40
+
41
+ it 'returns the block node' do
42
+ expect_object.subject_node.should be_block_type
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#to_node' do
48
+ context 'when the subject is a normal argument' do
49
+ let(:source) do
50
+ <<-END
51
+ describe 'example' do
52
+ it 'is empty' do
53
+ expect(subject).to be_empty
54
+ end
55
+ end
56
+ END
57
+ end
58
+
59
+ it 'returns #to node' do
60
+ method_name = expect_object.to_node.children[1]
61
+ method_name.should == :to
62
+ end
63
+ end
64
+
65
+ context 'when the subject is a block' do
66
+ let(:source) do
67
+ <<-END
68
+ describe 'example' do
69
+ it 'raises error' do
70
+ expect { do_something }.to raise_error
71
+ end
72
+ end
73
+ END
74
+ end
75
+
76
+ it 'returns #to node' do
77
+ method_name = expect_object.to_node.children[1]
78
+ method_name.should == :to
79
+ end
26
80
  end
27
81
  end
28
82
 
@@ -1049,6 +1049,64 @@ module Transpec
1049
1049
  end
1050
1050
  end
1051
1051
 
1052
+ context 'when it is `expect(method_returns_collection :some_arg).to have(2).items` form' do
1053
+ let(:source) do
1054
+ <<-END
1055
+ describe 'example' do
1056
+ it 'has 2 items' do
1057
+ expect(method_returns_collection :some_arg).to have(2).items
1058
+ end
1059
+ end
1060
+ END
1061
+ end
1062
+
1063
+ let(:expected_source) do
1064
+ <<-END
1065
+ describe 'example' do
1066
+ it 'has 2 items' do
1067
+ expect(method_returns_collection(:some_arg).size).to eq(2)
1068
+ end
1069
+ end
1070
+ END
1071
+ end
1072
+
1073
+ let(:have_object) { expect_object.have_matcher }
1074
+
1075
+ it 'converts into `expect(method_returns_collection(:some_arg).size).to eq(2)` form' do
1076
+ have_object.convert_to_standard_expectation!
1077
+ rewritten_source.should == expected_source
1078
+ end
1079
+ end
1080
+
1081
+ context 'when it is `expect(method_returns_collection(:some_arg) { do_something }).to have(2).items` form' do
1082
+ let(:source) do
1083
+ <<-END
1084
+ describe 'example' do
1085
+ it 'has 2 items' do
1086
+ expect(method_returns_collection(:some_arg) { do_something }).to have(2).items
1087
+ end
1088
+ end
1089
+ END
1090
+ end
1091
+
1092
+ let(:expected_source) do
1093
+ <<-END
1094
+ describe 'example' do
1095
+ it 'has 2 items' do
1096
+ expect(method_returns_collection(:some_arg) { do_something }.size).to eq(2)
1097
+ end
1098
+ end
1099
+ END
1100
+ end
1101
+
1102
+ let(:have_object) { expect_object.have_matcher }
1103
+
1104
+ it 'converts into `expect(method_returns_collection(:some_arg) { do_something }.size).to eq(2)` form' do
1105
+ have_object.convert_to_standard_expectation!
1106
+ rewritten_source.should == expected_source
1107
+ end
1108
+ end
1109
+
1052
1110
  context 'when it is `it { should have(2).items }` form' do
1053
1111
  let(:source) do
1054
1112
  <<-END
@@ -70,8 +70,8 @@ module Transpec
70
70
  END
71
71
  end
72
72
 
73
- it 'returns an instance of OperatorMatcher' do
74
- should be_an(OperatorMatcher)
73
+ it 'returns an instance of Operator' do
74
+ should be_an(Operator)
75
75
  end
76
76
  end
77
77
 
@@ -146,7 +146,7 @@ module Transpec
146
146
  END
147
147
  end
148
148
 
149
- it 'invokes OperatorMatcher#convert_operator!' do
149
+ it 'invokes Operator#convert_operator!' do
150
150
  should_object.operator_matcher.should_receive(:convert_operator!)
151
151
  should_object.expectize!
152
152
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
- require 'transpec/syntax/operator_matcher'
4
+ require 'transpec/syntax/operator'
5
5
  require 'transpec/syntax/should'
6
6
 
7
7
  module Transpec
8
8
  class Syntax
9
- describe OperatorMatcher do
9
+ describe Operator do
10
10
  include ::AST::Sexp
11
11
  include_context 'parsed objects'
12
12
  include_context 'syntax object', Should, :should_object
@@ -2,133 +2,58 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'transpec/syntax/raise_error'
5
+ require 'transpec/syntax/should'
6
+ require 'transpec/syntax/expect'
5
7
 
6
8
  module Transpec
7
9
  class Syntax
8
10
  describe RaiseError do
9
11
  include_context 'parsed objects'
10
- include_context 'syntax object', RaiseError, :raise_error_object
12
+ include_context 'syntax object', Should, :should_object
13
+ include_context 'syntax object', Expect, :expect_object
11
14
 
12
15
  let(:record) { raise_error_object.report.records.first }
13
16
 
14
- describe '#positive?' do
15
- subject { raise_error_object.positive? }
16
-
17
- context 'when it is `lambda { }.should raise_error` form' do
18
- let(:source) do
19
- <<-END
20
- describe 'example' do
21
- it 'raises error' do
22
- lambda { do_something }.should raise_error
23
- end
24
- end
25
- END
26
- end
27
-
28
- it { should be_true }
29
- end
30
-
31
- context 'when it is `expect { }.to raise_error` form' do
32
- let(:source) do
33
- <<-END
34
- describe 'example' do
35
- it 'raises error' do
36
- expect { do_something }.to raise_error
37
- end
38
- end
39
- END
40
- end
41
-
42
- it { should be_true }
43
- end
44
-
45
- context 'when it is `lambda { }.should raise_error { |error| ... }` form' do
46
- let(:source) do
47
- <<-END
48
- describe 'example' do
49
- it 'raises error' do
50
- lambda { do_something }.should raise_error { |error| do_anything }
51
- end
52
- end
53
- END
54
- end
55
-
56
- it { should be_true }
57
- end
58
-
59
- context 'when it is `expect { }.to raise_error { |error| ... }` form' do
60
- let(:source) do
61
- <<-END
62
- describe 'example' do
63
- it 'raises error' do
64
- expect { do_something }.to raise_error { |error| do_anything }
65
- end
66
- end
67
- END
68
- end
69
-
70
- it { should be_true }
17
+ describe '#remove_error_specification_with_negative_expectation!' do
18
+ before do
19
+ raise_error_object.remove_error_specification_with_negative_expectation!
71
20
  end
72
21
 
73
- context 'when it is `lambda { }.should_not raise_error` form' do
22
+ context 'when it is `lambda { }.should raise_error(SpecificErrorClass)` form' do
74
23
  let(:source) do
75
24
  <<-END
76
25
  describe 'example' do
77
- it 'does not raise error' do
78
- lambda { do_something }.should_not raise_error
26
+ it 'raises SpecificErrorClass' do
27
+ lambda { do_something }.should raise_error(SpecificErrorClass)
79
28
  end
80
29
  end
81
30
  END
82
31
  end
83
32
 
84
- it { should be_false }
85
- end
33
+ let(:raise_error_object) { should_object.raise_error_matcher }
86
34
 
87
- context 'when it is `expect { }.not_to raise_error` form' do
88
- let(:source) do
89
- <<-END
90
- describe 'example' do
91
- it 'does not raise error' do
92
- expect { do_something }.not_to raise_error
93
- end
94
- end
95
- END
35
+ it 'does nothing' do
36
+ rewritten_source.should == source
96
37
  end
97
38
 
98
- it { should be_false }
99
- end
100
-
101
- context 'when it is `expect { }.to_not raise_error` form' do
102
- let(:source) do
103
- <<-END
104
- describe 'example' do
105
- it 'does not raise error' do
106
- expect { do_something }.to_not raise_error
107
- end
108
- end
109
- END
39
+ it 'reports nothing' do
40
+ raise_error_object.report.records.should be_empty
110
41
  end
111
-
112
- it { should be_false }
113
- end
114
- end
115
-
116
- describe '#remove_error_specification_with_negative_expectation!' do
117
- before do
118
- raise_error_object.remove_error_specification_with_negative_expectation!
119
42
  end
120
43
 
121
- context 'when it is `lambda { }.should raise_error(SpecificErrorClass)` form' do
44
+ context 'when it is `expect { }.to raise_error(SpecificErrorClass)` form' do
122
45
  let(:source) do
123
46
  <<-END
124
47
  describe 'example' do
125
48
  it 'raises SpecificErrorClass' do
126
- lambda { do_something }.should raise_error(SpecificErrorClass)
49
+ expect { do_something }.to raise_error(SpecificErrorClass)
127
50
  end
128
51
  end
129
52
  END
130
53
  end
131
54
 
55
+ let(:raise_error_object) { expect_object.raise_error_matcher }
56
+
132
57
  it 'does nothing' do
133
58
  rewritten_source.should == source
134
59
  end
@@ -138,17 +63,19 @@ module Transpec
138
63
  end
139
64
  end
140
65
 
141
- context 'when it is `expect { }.to raise_error(SpecificErrorClass)` form' do
66
+ context 'when it is `lambda { }.should raise_error(SpecificErrorClass) { |error| ... }` form' do
142
67
  let(:source) do
143
68
  <<-END
144
69
  describe 'example' do
145
70
  it 'raises SpecificErrorClass' do
146
- expect { do_something }.to raise_error(SpecificErrorClass)
71
+ lambda { do_something }.should raise_error(SpecificErrorClass) { |error| do_anything }
147
72
  end
148
73
  end
149
74
  END
150
75
  end
151
76
 
77
+ let(:raise_error_object) { should_object.raise_error_matcher }
78
+
152
79
  it 'does nothing' do
153
80
  rewritten_source.should == source
154
81
  end
@@ -158,17 +85,19 @@ module Transpec
158
85
  end
159
86
  end
160
87
 
161
- context 'when it is `lambda { }.should raise_error(SpecificErrorClass) { |error| ... }` form' do
88
+ context 'when it is `expect { }.to raise_error(SpecificErrorClass) { |error| ... }` form' do
162
89
  let(:source) do
163
90
  <<-END
164
91
  describe 'example' do
165
92
  it 'raises SpecificErrorClass' do
166
- lambda { do_something }.should raise_error(SpecificErrorClass) { |error| do_anything }
93
+ expect { do_something }.to raise_error(SpecificErrorClass) { |error| do_anything }
167
94
  end
168
95
  end
169
96
  END
170
97
  end
171
98
 
99
+ let(:raise_error_object) { expect_object.raise_error_matcher }
100
+
172
101
  it 'does nothing' do
173
102
  rewritten_source.should == source
174
103
  end
@@ -178,17 +107,19 @@ module Transpec
178
107
  end
179
108
  end
180
109
 
181
- context 'when it is `expect { }.to raise_error(SpecificErrorClass) { |error| ... }` form' do
110
+ context 'when it is `expect { }.to raise_error(SpecificErrorClass).with_message(message)` form' do
182
111
  let(:source) do
183
112
  <<-END
184
113
  describe 'example' do
185
- it 'raises SpecificErrorClass' do
186
- expect { do_something }.to raise_error(SpecificErrorClass) { |error| do_anything }
114
+ it 'raises SpecificErrorClass with message' do
115
+ expect { do_something }.to raise_error(SpecificErrorClass).with_message(message)
187
116
  end
188
117
  end
189
118
  END
190
119
  end
191
120
 
121
+ let(:raise_error_object) { expect_object.raise_error_matcher }
122
+
192
123
  it 'does nothing' do
193
124
  rewritten_source.should == source
194
125
  end
@@ -219,6 +150,8 @@ module Transpec
219
150
  END
220
151
  end
221
152
 
153
+ let(:raise_error_object) { should_object.raise_error_matcher }
154
+
222
155
  it 'converts into `lambda { }.should_not raise_error` form' do
223
156
  rewritten_source.should == expected_source
224
157
  end
@@ -251,6 +184,8 @@ module Transpec
251
184
  END
252
185
  end
253
186
 
187
+ let(:raise_error_object) { expect_object.raise_error_matcher }
188
+
254
189
  it 'converts into `expect { }.not_to raise_error` form' do
255
190
  rewritten_source.should == expected_source
256
191
  end
@@ -277,6 +212,8 @@ module Transpec
277
212
  END
278
213
  end
279
214
 
215
+ let(:raise_error_object) { expect_object.raise_error_matcher }
216
+
280
217
  it 'converts into `expect { }.to_not raise_error` form' do
281
218
  rewritten_source.should == expected_source
282
219
  end
@@ -309,6 +246,8 @@ module Transpec
309
246
  END
310
247
  end
311
248
 
249
+ let(:raise_error_object) { expect_object.raise_error_matcher }
250
+
312
251
  it 'converts into `expect { }.not_to raise_error` form' do
313
252
  rewritten_source.should == expected_source
314
253
  end
@@ -341,6 +280,8 @@ module Transpec
341
280
  END
342
281
  end
343
282
 
283
+ let(:raise_error_object) { expect_object.raise_error_matcher }
284
+
344
285
  it 'converts into `expect { }.not_to raise_error` form' do
345
286
  rewritten_source.should == expected_source
346
287
  end
@@ -373,6 +314,8 @@ module Transpec
373
314
  END
374
315
  end
375
316
 
317
+ let(:raise_error_object) { expect_object.raise_error_matcher }
318
+
376
319
  it 'converts into `expect { }.not_to raise_error` form' do
377
320
  rewritten_source.should == expected_source
378
321
  end
@@ -93,8 +93,8 @@ module Transpec
93
93
  END
94
94
  end
95
95
 
96
- it 'returns an instance of OperatorMatcher' do
97
- should be_an(OperatorMatcher)
96
+ it 'returns an instance of Operator' do
97
+ should be_an(Operator)
98
98
  end
99
99
  end
100
100
 
@@ -179,7 +179,7 @@ module Transpec
179
179
  END
180
180
  end
181
181
 
182
- it 'invokes OperatorMatcher#convert_operator!' do
182
+ it 'invokes Operator#convert_operator!' do
183
183
  should_object.operator_matcher.should_receive(:convert_operator!)
184
184
  should_object.expectize!
185
185
  end
@@ -28,8 +28,18 @@ def generate_readme
28
28
  erb.result(binding)
29
29
  end
30
30
 
31
+ def select_sections(content, header_level, *section_names)
32
+ header_pattern = pattern_for_header_level(header_level)
33
+ sections = content.each_line.slice_before(header_pattern)
34
+
35
+ sections.select do |section|
36
+ header_line = section.first
37
+ section_names.any? { |name| header_line.include?(name) }
38
+ end
39
+ end
40
+
31
41
  def table_of_contents(lines, header_level)
32
- header_pattern = /^#{'#' * header_level}[^#]/
42
+ header_pattern = pattern_for_header_level(header_level)
33
43
 
34
44
  titles = lines.map do |line|
35
45
  next unless line.match(header_pattern)
@@ -41,3 +51,7 @@ def table_of_contents(lines, header_level)
41
51
  "* [#{title}](#{anchor})"
42
52
  end.join("\n")
43
53
  end
54
+
55
+ def pattern_for_header_level(level)
56
+ /^#{'#' * level}[^#]/
57
+ end
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.9.1
4
+ version: 1.9.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: 2014-02-15 00:00:00.000000000 Z
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -268,7 +268,7 @@ files:
268
268
  - lib/transpec/syntax/mixin/any_instance_block.rb
269
269
  - lib/transpec/syntax/mixin/expect_base.rb
270
270
  - lib/transpec/syntax/mixin/expectizable.rb
271
- - lib/transpec/syntax/mixin/have_matcher_owner.rb
271
+ - lib/transpec/syntax/mixin/matcher_owner.rb
272
272
  - lib/transpec/syntax/mixin/messaging_host.rb
273
273
  - lib/transpec/syntax/mixin/monkey_patch.rb
274
274
  - lib/transpec/syntax/mixin/monkey_patch_any_instance.rb
@@ -278,7 +278,7 @@ files:
278
278
  - lib/transpec/syntax/mixin/should_base.rb
279
279
  - lib/transpec/syntax/mixin/useless_and_return.rb
280
280
  - lib/transpec/syntax/oneliner_should.rb
281
- - lib/transpec/syntax/operator_matcher.rb
281
+ - lib/transpec/syntax/operator.rb
282
282
  - lib/transpec/syntax/raise_error.rb
283
283
  - lib/transpec/syntax/receive.rb
284
284
  - lib/transpec/syntax/rspec_configure.rb
@@ -320,7 +320,7 @@ files:
320
320
  - spec/transpec/syntax/matcher_definition_spec.rb
321
321
  - spec/transpec/syntax/method_stub_spec.rb
322
322
  - spec/transpec/syntax/oneliner_should_spec.rb
323
- - spec/transpec/syntax/operator_matcher_spec.rb
323
+ - spec/transpec/syntax/operator_spec.rb
324
324
  - spec/transpec/syntax/raise_error_spec.rb
325
325
  - spec/transpec/syntax/receive_spec.rb
326
326
  - spec/transpec/syntax/rspec_configure_spec.rb
@@ -391,7 +391,7 @@ test_files:
391
391
  - spec/transpec/syntax/matcher_definition_spec.rb
392
392
  - spec/transpec/syntax/method_stub_spec.rb
393
393
  - spec/transpec/syntax/oneliner_should_spec.rb
394
- - spec/transpec/syntax/operator_matcher_spec.rb
394
+ - spec/transpec/syntax/operator_spec.rb
395
395
  - spec/transpec/syntax/raise_error_spec.rb
396
396
  - spec/transpec/syntax/receive_spec.rb
397
397
  - spec/transpec/syntax/rspec_configure_spec.rb
@@ -1,38 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'active_support/concern'
4
- require 'transpec/syntax/have'
5
-
6
- module Transpec
7
- class Syntax
8
- module Mixin
9
- module HaveMatcherOwner
10
- extend ActiveSupport::Concern
11
-
12
- included do
13
- define_dynamic_analysis_request do |rewriter|
14
- if Have.dynamic_analysis_target_node?(matcher_node)
15
- create_have_matcher.register_request_for_dynamic_analysis(rewriter)
16
- end
17
- end
18
- end
19
-
20
- def have_matcher # rubocop:disable PredicateName
21
- return @have_matcher if instance_variable_defined?(:@have_matcher)
22
-
23
- @have_matcher ||= if Have.conversion_target_node?(matcher_node, @runtime_data)
24
- create_have_matcher
25
- else
26
- nil
27
- end
28
- end
29
-
30
- private
31
-
32
- def create_have_matcher
33
- Have.new(matcher_node, self, @source_rewriter, @runtime_data, @report)
34
- end
35
- end
36
- end
37
- end
38
- end