transpec 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -937,6 +937,44 @@ module Transpec
937
937
  end
938
938
  end
939
939
 
940
+ describe '#remove_useless_and_return!' do
941
+ before do
942
+ should_receive_object.remove_useless_and_return!
943
+ end
944
+
945
+ context 'when it is `subject.should_receive(:method).and_return { value }` form' do
946
+ let(:source) do
947
+ <<-END
948
+ describe 'example' do
949
+ it 'receives #foo and returns 1' do
950
+ subject.should_receive(:foo).and_return { 1 }
951
+ end
952
+ end
953
+ END
954
+ end
955
+
956
+ let(:expected_source) do
957
+ <<-END
958
+ describe 'example' do
959
+ it 'receives #foo and returns 1' do
960
+ subject.should_receive(:foo) { 1 }
961
+ end
962
+ end
963
+ END
964
+ end
965
+
966
+ it 'converts into `subject.should_receive(:method) { value }` form' do
967
+ rewritten_source.should == expected_source
968
+ end
969
+
970
+ it 'adds record ' \
971
+ '`obj.should_receive(:message).and_return { value }` -> `obj.should_receive(:message) { value }`' do
972
+ record.original_syntax.should == 'obj.should_receive(:message).and_return { value }'
973
+ record.converted_syntax.should == 'obj.should_receive(:message) { value }'
974
+ end
975
+ end
976
+ end
977
+
940
978
  describe '#add_receiver_arg_to_any_instance_implementation_block!' do
941
979
  before do
942
980
  should_receive_object.add_receiver_arg_to_any_instance_implementation_block!
@@ -12,7 +12,9 @@ module Transpec
12
12
  let(:record) { should_object.report.records.first }
13
13
 
14
14
  describe '#matcher_node' do
15
- context 'when it is taking operator matcher' do
15
+ let(:matcher_name) { should_object.matcher_node.children[1] }
16
+
17
+ context 'when the matcher is operator' do
16
18
  let(:source) do
17
19
  <<-END
18
20
  describe 'example' do
@@ -23,22 +25,12 @@ module Transpec
23
25
  END
24
26
  end
25
27
 
26
- # (block
27
- # (send nil :it
28
- # (str "is 1"))
29
- # (args)
30
- # (send
31
- # (send
32
- # (send nil :subject) :should) :==
33
- # (int 1)))
34
-
35
- it 'returns its parent node' do
36
- should_object.parent_node.children[1].should == :==
37
- should_object.matcher_node.should == should_object.parent_node
28
+ it 'returns the matcher node' do
29
+ matcher_name.should == :==
38
30
  end
39
31
  end
40
32
 
41
- context 'when it is taking non-operator matcher without argument' do
33
+ context 'when the matcher is not operator' do
42
34
  let(:source) do
43
35
  <<-END
44
36
  describe 'example' do
@@ -49,43 +41,40 @@ module Transpec
49
41
  END
50
42
  end
51
43
 
52
- # (block
53
- # (send nil :it
54
- # (str "is empty"))
55
- # (args)
56
- # (send
57
- # (send nil :subject) :should
58
- # (send nil :be_empty)))
59
-
60
- it 'returns its argument node' do
61
- should_object.arg_node.children[1].should == :be_empty
62
- should_object.matcher_node.should == should_object.arg_node
44
+ it 'returns the matcher node' do
45
+ matcher_name.should == :be_empty
63
46
  end
64
47
  end
65
48
 
66
- context 'when it is taking non-operator matcher with argument' do
49
+ context 'when the matcher is chained by another method' do
67
50
  let(:source) do
68
51
  <<-END
69
52
  describe 'example' do
70
- it 'is 1' do
71
- subject.should eq(1)
53
+ it 'has 2 items' do
54
+ subject.should have(2).items
72
55
  end
73
56
  end
74
57
  END
75
58
  end
76
59
 
77
- # (block
78
- # (send nil :it
79
- # (str "is 1"))
80
- # (args)
81
- # (send
82
- # (send nil :subject) :should
83
- # (send nil :eq
84
- # (int 1))))
60
+ it 'returns the matcher node' do
61
+ matcher_name.should == :have
62
+ end
63
+ end
64
+
65
+ context 'when the matcher is chained by another method that is taking a block' do
66
+ let(:source) do
67
+ <<-END
68
+ describe 'example' do
69
+ it 'has 2 items' do
70
+ subject.should have(2).items { }
71
+ end
72
+ end
73
+ END
74
+ end
85
75
 
86
- it 'returns its argument node' do
87
- should_object.arg_node.children[1].should == :eq
88
- should_object.matcher_node.should == should_object.arg_node
76
+ it 'returns the first node of the chain' do
77
+ matcher_name.should == :have
89
78
  end
90
79
  end
91
80
  end
@@ -23,7 +23,21 @@ def generate_readme
23
23
  require 'erb'
24
24
  require 'transpec/cli'
25
25
 
26
- text = File.read('README.md.erb')
27
- erb = ERB.new(text, nil, '-')
26
+ readme = File.read('README.md.erb')
27
+ erb = ERB.new(readme, nil, '-')
28
28
  erb.result(binding)
29
29
  end
30
+
31
+ def table_of_contents(lines, header_level)
32
+ header_pattern = /^#{'#' * header_level}[^#]/
33
+
34
+ titles = lines.map do |line|
35
+ next unless line.match(header_pattern)
36
+ line.sub(/^[#\s]*/, '').chomp
37
+ end.compact
38
+
39
+ titles.map do |title|
40
+ anchor = '#' + title.gsub(/[^\w_\- ]/, '').downcase.gsub(' ', '-')
41
+ "* [#{title}](#{anchor})"
42
+ end.join("\n")
43
+ 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.8.0
4
+ version: 1.9.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: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -262,16 +262,18 @@ files:
262
262
  - lib/transpec/syntax/its.rb
263
263
  - lib/transpec/syntax/matcher_definition.rb
264
264
  - lib/transpec/syntax/method_stub.rb
265
- - lib/transpec/syntax/mixin/allow_no_message.rb
266
265
  - lib/transpec/syntax/mixin/any_instance_block.rb
267
266
  - lib/transpec/syntax/mixin/expect_base.rb
268
267
  - lib/transpec/syntax/mixin/expectizable.rb
269
268
  - lib/transpec/syntax/mixin/have_matcher_owner.rb
269
+ - lib/transpec/syntax/mixin/messaging_host.rb
270
270
  - lib/transpec/syntax/mixin/monkey_patch.rb
271
271
  - lib/transpec/syntax/mixin/monkey_patch_any_instance.rb
272
+ - lib/transpec/syntax/mixin/no_message_allowance.rb
272
273
  - lib/transpec/syntax/mixin/owned_matcher.rb
273
274
  - lib/transpec/syntax/mixin/send.rb
274
275
  - lib/transpec/syntax/mixin/should_base.rb
276
+ - lib/transpec/syntax/mixin/useless_and_return.rb
275
277
  - lib/transpec/syntax/oneliner_should.rb
276
278
  - lib/transpec/syntax/operator_matcher.rb
277
279
  - lib/transpec/syntax/raise_error.rb