transpec 0.1.3 → 0.2.0
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 +5 -0
- data/README.md +35 -3
- data/README.md.erb +35 -3
- data/lib/transpec/cli.rb +50 -4
- data/lib/transpec/commit_message.rb +25 -0
- data/lib/transpec/git.rb +18 -0
- data/lib/transpec/record.rb +28 -0
- data/lib/transpec/report.rb +109 -0
- data/lib/transpec/rewriter.rb +17 -8
- data/lib/transpec/syntax.rb +25 -22
- data/lib/transpec/syntax/be_close.rb +6 -0
- data/lib/transpec/syntax/double.rb +5 -0
- data/lib/transpec/syntax/matcher.rb +17 -1
- data/lib/transpec/syntax/method_stub.rb +40 -8
- data/lib/transpec/syntax/raise_error.rb +17 -0
- data/lib/transpec/syntax/send_node_syntax.rb +4 -0
- data/lib/transpec/syntax/should.rb +23 -2
- data/lib/transpec/syntax/should_receive.rb +54 -2
- data/lib/transpec/version.rb +2 -2
- data/spec/.rubocop.yml +1 -1
- data/spec/support/shared_context.rb +10 -0
- data/spec/transpec/cli_spec.rb +76 -29
- data/spec/transpec/commit_message_spec.rb +63 -0
- data/spec/transpec/configuration_spec.rb +1 -1
- data/spec/transpec/git_spec.rb +114 -38
- data/spec/transpec/record_spec.rb +18 -0
- data/spec/transpec/report_spec.rb +89 -0
- data/spec/transpec/rewriter_spec.rb +5 -0
- data/spec/transpec/syntax/be_close_spec.rb +10 -1
- data/spec/transpec/syntax/double_spec.rb +10 -0
- data/spec/transpec/syntax/matcher_spec.rb +31 -0
- data/spec/transpec/syntax/method_stub_spec.rb +53 -44
- data/spec/transpec/syntax/raise_error_spec.rb +64 -24
- data/spec/transpec/syntax/should_receive_spec.rb +67 -7
- data/spec/transpec/syntax/should_spec.rb +26 -0
- data/tasks/test.rake +27 -12
- metadata +11 -2
data/lib/transpec/version.rb
CHANGED
data/spec/.rubocop.yml
CHANGED
data/spec/transpec/cli_spec.rb
CHANGED
@@ -25,20 +25,40 @@ module Transpec
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
describe '#generates_commit_message?' do
|
29
|
+
subject { cli.generates_commit_message? }
|
30
|
+
|
31
|
+
context 'by default' do
|
32
|
+
it { should be_false }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
28
36
|
describe '#run' do
|
37
|
+
include_context 'isolated environment'
|
38
|
+
|
39
|
+
subject { cli.run(args) }
|
40
|
+
|
41
|
+
let(:args) { [file_path] }
|
42
|
+
let(:file_path) { 'spec/example_spec.rb' }
|
43
|
+
let(:file_content) do
|
44
|
+
<<-END
|
45
|
+
describe 'something' do
|
46
|
+
it 'is 1' do
|
47
|
+
1.should == 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
END
|
51
|
+
end
|
52
|
+
|
29
53
|
before do
|
30
54
|
cli.stub(:puts)
|
31
55
|
cli.stub(:warn)
|
32
|
-
|
56
|
+
create_file(file_path, file_content)
|
33
57
|
end
|
34
58
|
|
35
|
-
subject { cli.run(args) }
|
36
|
-
let(:args) { ['some_file.rb'] }
|
37
|
-
let(:rewriter) { double('rewriter').as_null_object }
|
38
|
-
|
39
59
|
shared_examples 'rewrites files' do
|
40
60
|
it 'rewrites files' do
|
41
|
-
|
61
|
+
cli.should_receive(:process_file)
|
42
62
|
cli.run(args)
|
43
63
|
end
|
44
64
|
|
@@ -47,15 +67,7 @@ module Transpec
|
|
47
67
|
end
|
48
68
|
end
|
49
69
|
|
50
|
-
shared_context 'stubbed rewriter' do
|
51
|
-
before do
|
52
|
-
Rewriter.stub(:new).and_return(rewriter)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
70
|
context 'when git is available' do
|
57
|
-
include_context 'stubbed rewriter'
|
58
|
-
|
59
71
|
before { Git.stub(:command_available?).and_return(true) }
|
60
72
|
|
61
73
|
context 'and inside of a repository' do
|
@@ -68,7 +80,7 @@ module Transpec
|
|
68
80
|
before { cli.stub(:forced?).and_return(false) }
|
69
81
|
|
70
82
|
it 'aborts processing' do
|
71
|
-
|
83
|
+
cli.should_not_receive(:process_file)
|
72
84
|
cli.run(args).should be_false
|
73
85
|
end
|
74
86
|
|
@@ -100,14 +112,11 @@ module Transpec
|
|
100
112
|
end
|
101
113
|
|
102
114
|
context 'when git is not available' do
|
103
|
-
include_context 'stubbed rewriter'
|
104
115
|
before { Git.stub(:command_available?).and_return(false) }
|
105
116
|
include_examples 'rewrites files'
|
106
117
|
end
|
107
118
|
|
108
119
|
context 'when a syntax error is raised while processing files' do
|
109
|
-
include_context 'isolated environment'
|
110
|
-
|
111
120
|
let(:args) { [invalid_syntax_file_path, valid_syntax_file_path] }
|
112
121
|
let(:invalid_syntax_file_path) { 'invalid_example.rb' }
|
113
122
|
let(:valid_syntax_file_path) { 'valid_example.rb' }
|
@@ -133,30 +142,23 @@ module Transpec
|
|
133
142
|
end
|
134
143
|
|
135
144
|
context 'when any other error is raised while running' do
|
136
|
-
|
137
|
-
|
138
|
-
before do
|
139
|
-
cli.stub(:parse_options).and_raise(ArgumentError, 'No such file or directory - non-existent-file')
|
140
|
-
end
|
145
|
+
let(:args) { ['non-existent-file'] }
|
141
146
|
|
142
147
|
it 'return false' do
|
143
148
|
should be_false
|
144
149
|
end
|
145
150
|
|
146
151
|
it 'prints message of the exception' do
|
147
|
-
cli.should_receive(:warn).with(
|
148
|
-
cli.run(
|
152
|
+
cli.should_receive(:warn).with(/No such file or directory/)
|
153
|
+
cli.run(args)
|
149
154
|
end
|
150
155
|
end
|
151
156
|
|
152
157
|
context 'when no target paths are specified' do
|
153
|
-
include_context 'isolated environment'
|
154
|
-
include_context 'stubbed rewriter'
|
155
|
-
|
156
158
|
let(:args) { [] }
|
157
159
|
|
158
160
|
context 'and there is "spec" directory' do
|
159
|
-
|
161
|
+
let(:file_path) { 'spec/example_spec.rb' }
|
160
162
|
|
161
163
|
it 'targets files in the "spec" directoy' do
|
162
164
|
cli.should_receive(:target_files).with(['spec'])
|
@@ -165,11 +167,35 @@ module Transpec
|
|
165
167
|
end
|
166
168
|
|
167
169
|
context 'and there is not "spec" directory' do
|
170
|
+
let(:file_path) { 'example_spec.rb' }
|
171
|
+
|
168
172
|
it 'aborts' do
|
169
173
|
should be_false
|
170
174
|
end
|
171
175
|
end
|
172
176
|
end
|
177
|
+
|
178
|
+
context 'when -m/--commit-message option is specified' do
|
179
|
+
include_context 'inside of git repository'
|
180
|
+
|
181
|
+
let(:args) { ['--force', '--commit-message', file_path] }
|
182
|
+
|
183
|
+
context 'and any conversion is done' do
|
184
|
+
it 'writes commit message to .git/COMMIT_EDITMSG' do
|
185
|
+
cli.run(args)
|
186
|
+
File.read('.git/COMMIT_EDITMSG').should start_with('Convert specs')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'and no conversion is done' do
|
191
|
+
let(:file_content) { '' }
|
192
|
+
|
193
|
+
it 'does not writes commit message' do
|
194
|
+
cli.run(args)
|
195
|
+
File.exist?('.git/COMMIT_EDITMSG').should be_false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
173
199
|
end
|
174
200
|
|
175
201
|
describe '#process_file' do
|
@@ -232,6 +258,27 @@ module Transpec
|
|
232
258
|
end
|
233
259
|
end
|
234
260
|
|
261
|
+
describe '-m/--commit-message option' do
|
262
|
+
include_context 'isolated environment'
|
263
|
+
|
264
|
+
let(:args) { ['--commit-message'] }
|
265
|
+
|
266
|
+
context 'when inside of git repository' do
|
267
|
+
include_context 'inside of git repository'
|
268
|
+
|
269
|
+
it 'sets #generates_commit_message? true' do
|
270
|
+
cli.parse_options(args)
|
271
|
+
cli.generates_commit_message?.should be_true
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when not inside of git repository' do
|
276
|
+
it 'raises error' do
|
277
|
+
-> { cli.parse_options(args) }.should raise_error(/not in a Git repository/)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
235
282
|
describe '-d/--disable option' do
|
236
283
|
[
|
237
284
|
['expect_to_matcher', :convert_to_expect_to_matcher?],
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'transpec/commit_message'
|
5
|
+
require 'transpec/report'
|
6
|
+
require 'transpec/record'
|
7
|
+
|
8
|
+
module Transpec
|
9
|
+
describe CommitMessage do
|
10
|
+
subject(:commit_message) { CommitMessage.new(report, cli_args) }
|
11
|
+
let(:report) { Report.new }
|
12
|
+
let(:cli_args) { %w(--force --commit-message) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
report.records << Record.new('obj.stub(:message)', 'allow(obj).to receive(:message)')
|
16
|
+
report.records << Record.new('obj.should', 'expect(obj).to')
|
17
|
+
report.records << Record.new('obj.should', 'expect(obj).to')
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#to_s' do
|
21
|
+
it 'wraps lines within 72 characters' do
|
22
|
+
commit_message.to_s.each_line do |line|
|
23
|
+
line.chomp.size.should <= 72
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:lines) { commit_message.to_s.lines.to_a }
|
28
|
+
|
29
|
+
it 'has concise summary at first line' do
|
30
|
+
lines[0].chomp.should == 'Convert specs to latest RSpec syntax with Transpec'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has blank line at second line' do
|
34
|
+
lines[1].chomp.should be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:body_lines) { lines[2..-1] }
|
38
|
+
|
39
|
+
it 'has Transpec description at the beginning of the body' do
|
40
|
+
body_lines[0].chomp
|
41
|
+
.should match(/^This conversion is done by Transpec \d+\.\d+\.\d+ with the following command:$/)
|
42
|
+
body_lines[1].chomp
|
43
|
+
.should == ' transpec --force --commit-message'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has blank line after the preface in the body' do
|
47
|
+
body_lines[2].chomp.should be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'has conversion summary in the body' do
|
51
|
+
body_lines[3..-1].join('').should == <<-END.gsub(/^\s+\|/, '')
|
52
|
+
|* 2 conversions
|
53
|
+
| from: obj.should
|
54
|
+
| to: expect(obj).to
|
55
|
+
|
|
56
|
+
|* 1 conversion
|
57
|
+
| from: obj.stub(:message)
|
58
|
+
| to: allow(obj).to receive(:message)
|
59
|
+
END
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/transpec/git_spec.rb
CHANGED
@@ -20,66 +20,142 @@ module Transpec
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
shared_context 'inside of git repository' do
|
24
|
-
around do |example|
|
25
|
-
Dir.mkdir('repo')
|
26
|
-
Dir.chdir('repo') do
|
27
|
-
`git init`
|
28
|
-
example.run
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
23
|
describe '.inside_of_repository?' do
|
34
24
|
subject { Git.inside_of_repository? }
|
35
25
|
|
36
|
-
context 'when
|
37
|
-
|
38
|
-
|
26
|
+
context 'when git command is avaialable' do
|
27
|
+
context 'and the current directory is inside of git repository' do
|
28
|
+
include_context 'inside of git repository'
|
29
|
+
it { should be_true }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'and the current directory is not inside of git repository' do
|
33
|
+
it { should be_false }
|
34
|
+
end
|
39
35
|
end
|
40
36
|
|
41
|
-
context 'when
|
42
|
-
|
37
|
+
context 'when git command is not avaialable' do
|
38
|
+
before { Git.stub(:command_available?).and_return(false) }
|
39
|
+
|
40
|
+
it 'raises error' do
|
41
|
+
-> { Git.inside_of_repository? }.should raise_error(/command is not available/)
|
42
|
+
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '.clean?' do
|
47
|
-
include_context 'inside of git repository'
|
48
|
-
|
49
47
|
subject { Git.clean? }
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
`git add .`
|
54
|
-
`git commit -m 'Initial commit'`
|
55
|
-
end
|
49
|
+
context 'when inside of git repository' do
|
50
|
+
include_context 'inside of git repository'
|
56
51
|
|
57
|
-
|
58
|
-
|
52
|
+
before do
|
53
|
+
File.write('foo', 'This is a sample file')
|
54
|
+
`git add .`
|
55
|
+
`git commit -m 'Initial commit'`
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'and there are no changes' do
|
59
|
+
it { should be_true }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'and there is an untracked file' do
|
63
|
+
before { File.write('bar', 'This is an untracked file') }
|
64
|
+
it { should be_false }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'and there is a deleted file' do
|
68
|
+
before { File.delete('foo') }
|
69
|
+
it { should be_false }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'and there is a not staged change' do
|
73
|
+
before { File.write('foo', 'This is modified content') }
|
74
|
+
it { should be_false }
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'and there is a staged change' do
|
78
|
+
before do
|
79
|
+
File.write('foo', 'This is modified content')
|
80
|
+
`git add .`
|
81
|
+
end
|
82
|
+
|
83
|
+
it { should be_false }
|
84
|
+
end
|
59
85
|
end
|
60
86
|
|
61
|
-
context 'when
|
62
|
-
|
63
|
-
|
87
|
+
context 'when not inside of git repository' do
|
88
|
+
it 'raises error' do
|
89
|
+
-> { Git.clean? }.should raise_error(/is not a Git repository/)
|
90
|
+
end
|
64
91
|
end
|
92
|
+
end
|
65
93
|
|
66
|
-
|
67
|
-
|
68
|
-
|
94
|
+
describe '.repository_root' do
|
95
|
+
context 'when inside of git repository' do
|
96
|
+
include_context 'inside of git repository'
|
97
|
+
|
98
|
+
context 'and the current working directory is the repository root' do
|
99
|
+
it 'returns the repository root path' do
|
100
|
+
Git.repository_root.should == File.expand_path('.')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'and the current working directory is not the repository root' do
|
105
|
+
around do |example|
|
106
|
+
Dir.mkdir('dir')
|
107
|
+
Dir.chdir('dir') do
|
108
|
+
example.run
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'returns the repository root path' do
|
113
|
+
Git.repository_root.should == File.expand_path('..')
|
114
|
+
end
|
115
|
+
end
|
69
116
|
end
|
70
117
|
|
71
|
-
context 'when
|
72
|
-
|
73
|
-
|
118
|
+
context 'when not inside of git repository' do
|
119
|
+
it 'raises error' do
|
120
|
+
-> { Git.repository_root }.should raise_error(/is not a Git repository/)
|
121
|
+
end
|
74
122
|
end
|
123
|
+
end
|
75
124
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
125
|
+
describe '.write_commit_message' do
|
126
|
+
let(:message) { 'This is the commit message.' }
|
127
|
+
|
128
|
+
context 'when inside of git repository' do
|
129
|
+
include_context 'inside of git repository'
|
130
|
+
|
131
|
+
context 'and there is .git directory in the current working directory' do
|
132
|
+
it 'writes the message to .git/COMMIT_EDITMSG' do
|
133
|
+
Git.write_commit_message(message)
|
134
|
+
File.read('.git/COMMIT_EDITMSG').should == message
|
135
|
+
end
|
80
136
|
end
|
81
137
|
|
82
|
-
|
138
|
+
context 'and there is not .git directory in the current working directory' do
|
139
|
+
around do |example|
|
140
|
+
Dir.mkdir('dir')
|
141
|
+
Dir.chdir('dir') do
|
142
|
+
example.run
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'writes the message to .git/COMMIT_EDITMSG in repository root directory' do
|
147
|
+
Git.write_commit_message(message)
|
148
|
+
File.read('../.git/COMMIT_EDITMSG').should == message
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when not inside of git repository' do
|
154
|
+
it 'raises error' do
|
155
|
+
lambda do
|
156
|
+
Git.write_commit_message(message)
|
157
|
+
end.should raise_error(/is not a Git repository/)
|
158
|
+
end
|
83
159
|
end
|
84
160
|
end
|
85
161
|
end
|