transpec 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +4 -0
  4. data/lib/transpec/version.rb +1 -1
  5. data/transpec.gemspec +4 -3
  6. metadata +3 -97
  7. data/spec/.rubocop.yml +0 -23
  8. data/spec/integration/configuration_modification_spec.rb +0 -186
  9. data/spec/integration/conversion_spec.rb +0 -145
  10. data/spec/spec_helper.rb +0 -52
  11. data/spec/support/cache_helper.rb +0 -62
  12. data/spec/support/file_helper.rb +0 -25
  13. data/spec/support/shared_context.rb +0 -84
  14. data/spec/transpec/cli_spec.rb +0 -341
  15. data/spec/transpec/commit_message_spec.rb +0 -81
  16. data/spec/transpec/config_spec.rb +0 -99
  17. data/spec/transpec/converter_spec.rb +0 -1374
  18. data/spec/transpec/directory_cloner_spec.rb +0 -74
  19. data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +0 -143
  20. data/spec/transpec/dynamic_analyzer_spec.rb +0 -329
  21. data/spec/transpec/git_spec.rb +0 -151
  22. data/spec/transpec/option_parser_spec.rb +0 -275
  23. data/spec/transpec/processed_source_spec.rb +0 -93
  24. data/spec/transpec/project_spec.rb +0 -194
  25. data/spec/transpec/record_spec.rb +0 -128
  26. data/spec/transpec/report_spec.rb +0 -126
  27. data/spec/transpec/rspec_version_spec.rb +0 -129
  28. data/spec/transpec/spec_file_finder_spec.rb +0 -118
  29. data/spec/transpec/spec_suite_spec.rb +0 -108
  30. data/spec/transpec/static_context_inspector_spec.rb +0 -713
  31. data/spec/transpec/syntax/allow_spec.rb +0 -122
  32. data/spec/transpec/syntax/be_boolean_spec.rb +0 -176
  33. data/spec/transpec/syntax/be_close_spec.rb +0 -51
  34. data/spec/transpec/syntax/current_example_spec.rb +0 -319
  35. data/spec/transpec/syntax/double_spec.rb +0 -175
  36. data/spec/transpec/syntax/example_group_spec.rb +0 -716
  37. data/spec/transpec/syntax/example_spec.rb +0 -301
  38. data/spec/transpec/syntax/expect_spec.rb +0 -313
  39. data/spec/transpec/syntax/have_spec.rb +0 -1276
  40. data/spec/transpec/syntax/hook_spec.rb +0 -215
  41. data/spec/transpec/syntax/its_spec.rb +0 -448
  42. data/spec/transpec/syntax/matcher_definition_spec.rb +0 -59
  43. data/spec/transpec/syntax/method_stub_spec.rb +0 -1301
  44. data/spec/transpec/syntax/oneliner_should_spec.rb +0 -628
  45. data/spec/transpec/syntax/operator_spec.rb +0 -871
  46. data/spec/transpec/syntax/pending_spec.rb +0 -415
  47. data/spec/transpec/syntax/raise_error_spec.rb +0 -354
  48. data/spec/transpec/syntax/receive_spec.rb +0 -499
  49. data/spec/transpec/syntax/rspec_configure_spec.rb +0 -870
  50. data/spec/transpec/syntax/should_receive_spec.rb +0 -1108
  51. data/spec/transpec/syntax/should_spec.rb +0 -497
  52. data/spec/transpec/util_spec.rb +0 -115
  53. data/spec/transpec_spec.rb +0 -22
@@ -1,151 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'transpec/git'
5
-
6
- module Transpec
7
- describe Git do
8
- include_context 'isolated environment'
9
-
10
- describe '.command_available?' do
11
- subject { Git.command_available? }
12
-
13
- context 'when git command is found in PATH' do
14
- it { should be_true }
15
- end
16
-
17
- context 'when git command is not found in PATH' do
18
- before { stub_const('Transpec::Git::GIT', 'non-existent-command') }
19
- it { should be_false }
20
- end
21
- end
22
-
23
- describe '.inside_of_repository?' do
24
- subject { Git.inside_of_repository? }
25
-
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
35
- end
36
-
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
- end
44
- end
45
-
46
- describe '.clean?' do
47
- subject { Git.clean? }
48
-
49
- context 'when inside of git repository' do
50
- include_context 'inside of git repository'
51
-
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
85
- end
86
-
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
91
- end
92
- end
93
-
94
- describe '.write_commit_message' do
95
- let(:message) { 'This is the commit message.' }
96
-
97
- context 'when inside of standard git-dir (.git) repository' do
98
- include_context 'inside of git repository'
99
-
100
- context 'and the current working directory is the repository root' do
101
- it 'writes the message to .git/COMMIT_EDITMSG' do
102
- Git.write_commit_message(message)
103
- File.read('.git/COMMIT_EDITMSG').should == message
104
- end
105
- end
106
-
107
- context 'and the current working directory is not the repository root' do
108
- around do |example|
109
- Dir.mkdir('dir')
110
- Dir.chdir('dir') do
111
- example.run
112
- end
113
- end
114
-
115
- it 'writes the message to .git/COMMIT_EDITMSG in the repository root' do
116
- Git.write_commit_message(message)
117
- File.read('../.git/COMMIT_EDITMSG').should == message
118
- end
119
- end
120
-
121
- it 'returns the commit message file path' do
122
- path = Git.write_commit_message(message)
123
- File.read(path).should == message
124
- end
125
- end
126
-
127
- context 'when inside of separated git-dir repository' do
128
- around do |example|
129
- Dir.mkdir('repo')
130
- Dir.chdir('repo') do
131
- `git init --separate-git-dir this-is-git-dir`
132
- example.run
133
- end
134
- end
135
-
136
- it 'writes the message to COMMIT_EDITMSG in the separated git-dir' do
137
- Git.write_commit_message(message)
138
- File.read('this-is-git-dir/COMMIT_EDITMSG').should == message
139
- end
140
- end
141
-
142
- context 'when not inside of git repository' do
143
- it 'raises error' do
144
- lambda do
145
- Git.write_commit_message(message)
146
- end.should raise_error(/is not a Git repository/)
147
- end
148
- end
149
- end
150
- end
151
- end
@@ -1,275 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'transpec/option_parser'
5
-
6
- module Transpec
7
- describe OptionParser do
8
- subject(:parser) { OptionParser.new(config) }
9
- let(:config) { Config.new }
10
-
11
- describe '#parse' do
12
- subject { parser.parse(args) }
13
- let(:args) { ['some_file', '--negative-form', 'to_not', 'some_dir'] }
14
-
15
- it 'return non-option arguments' do
16
- should == ['some_file', 'some_dir']
17
- end
18
-
19
- it 'does not mutate the passed array' do
20
- parser.parse(args)
21
- args.should == ['some_file', '--negative-form', 'to_not', 'some_dir']
22
- end
23
-
24
- describe '-f/--force option' do
25
- let(:args) { ['--force'] }
26
-
27
- it 'sets Config#forced? true' do
28
- parser.parse(args)
29
- config.forced?.should be_true
30
- end
31
- end
32
-
33
- describe '-s/--skip-dynamic-analysis option' do
34
- let(:args) { ['--skip-dynamic-analysis'] }
35
-
36
- it 'sets Config#skip_dynamic_analysis? true' do
37
- parser.parse(args)
38
- config.skip_dynamic_analysis?.should be_true
39
- end
40
- end
41
-
42
- describe '-k/--keep option' do
43
- [
44
- ['should', :convert_should?],
45
- ['oneliner', :convert_oneliner?],
46
- ['should_receive', :convert_should_receive?],
47
- ['stub', :convert_stub?],
48
- ['have_items', :convert_have_items?],
49
- ['its', :convert_its?],
50
- ['pending', :convert_pending?],
51
- ['deprecated', :convert_deprecated_method?]
52
- ].each do |cli_type, config_attr|
53
- context "when #{cli_type.inspect} is specified" do
54
- let(:args) { ['--keep', cli_type] }
55
-
56
- it "sets Config##{config_attr} false" do
57
- parser.parse(args)
58
- config.send(config_attr).should be_false
59
- end
60
- end
61
- end
62
-
63
- context 'when multiple types are specified with comma' do
64
- let(:args) { ['--keep', 'should_receive,deprecated'] }
65
-
66
- it 'handles all of them' do
67
- parser.parse(args)
68
- config.convert_should_receive?.should be_false
69
- config.convert_deprecated_method?.should be_false
70
- end
71
- end
72
-
73
- context 'when unknown type is specified' do
74
- let(:args) { ['--keep', 'unknown'] }
75
-
76
- it 'raises error' do
77
- -> { parser.parse(args) }.should raise_error(ArgumentError) { |error|
78
- error.message.should == 'Unknown syntax type "unknown"'
79
- }
80
- end
81
- end
82
- end
83
-
84
- describe '-v/--convert option' do
85
- [
86
- ['example_group', :convert_example_group?],
87
- ['hook_scope', :convert_hook_scope?],
88
- ['stub_with_hash', :convert_stub_with_hash_to_allow_to_receive_and_return?]
89
- ].each do |cli_type, config_attr|
90
- context "when #{cli_type.inspect} is specified" do
91
- let(:args) { ['--convert', cli_type] }
92
-
93
- it "sets Config##{config_attr} true" do
94
- parser.parse(args)
95
- config.send(config_attr).should be_true
96
- end
97
- end
98
- end
99
-
100
- context 'when unknown type is specified' do
101
- let(:args) { ['--convert', 'unknown'] }
102
-
103
- it 'raises error' do
104
- -> { parser.parse(args) }.should raise_error(ArgumentError) { |error|
105
- error.message.should == 'Unknown syntax type "unknown"'
106
- }
107
- end
108
- end
109
- end
110
-
111
- describe '-n/--negative-form option' do
112
- ['not_to', 'to_not'].each do |form|
113
- context "when #{form.inspect} is specified" do
114
- let(:args) { ['--negative-form', form] }
115
-
116
- it "sets Config#negative_form_of_to #{form.inspect}" do
117
- parser.parse(args)
118
- config.negative_form_of_to.should == form
119
- end
120
- end
121
- end
122
- end
123
-
124
- describe '-b/--boolean-matcher option' do
125
- [
126
- ['truthy,falsey', :conditional, 'be_falsey'],
127
- ['truthy,falsy', :conditional, 'be_falsy'],
128
- ['true,false', :exact, 'be_falsey']
129
- ].each do |cli_type, config_type, form_of_be_falsey|
130
- context "when #{cli_type.inspect} is specified" do
131
- let(:args) { ['--boolean-matcher', cli_type] }
132
-
133
- it "sets Config#boolean_matcher_type #{config_type.inspect}" do
134
- parser.parse(args)
135
- config.boolean_matcher_type.should == config_type
136
- end
137
-
138
- it "sets Config#form_of_be_falsey #{form_of_be_falsey.inspect}" do
139
- parser.parse(args)
140
- config.form_of_be_falsey.should == form_of_be_falsey
141
- end
142
- end
143
- end
144
-
145
- ['', 'truthy', 'true', 'foo'].each do |cli_type|
146
- context "when #{cli_type.inspect} is specified" do
147
- let(:args) { ['--boolean-matcher', cli_type] }
148
-
149
- it 'raises error' do
150
- -> { parser.parse(args) }.should raise_error(/must be any of/)
151
- end
152
- end
153
- end
154
- end
155
-
156
- describe '-a/--no-yield-any-instance option' do
157
- let(:args) { ['--no-yield-any-instance'] }
158
-
159
- it 'sets Config#add_receiver_arg_to_any_instance_implementation_block? false' do
160
- parser.parse(args)
161
- config.add_receiver_arg_to_any_instance_implementation_block?
162
- .should be_false
163
- end
164
- end
165
-
166
- describe '-e/--explicit-spec-type option' do
167
- let(:args) { ['--explicit-spec-type'] }
168
-
169
- it 'sets Config#add_explicit_type_metadata_to_example_group? true' do
170
- parser.parse(args)
171
- config.add_explicit_type_metadata_to_example_group?.should be_true
172
- end
173
- end
174
-
175
- describe '-p/--no-parens-matcher-arg option' do
176
- let(:args) { ['--no-parens-matcher-arg'] }
177
-
178
- it 'sets Config#parenthesize_matcher_arg? false' do
179
- parser.parse(args)
180
- config.parenthesize_matcher_arg.should be_false
181
- end
182
- end
183
-
184
- describe '--no-parentheses-matcher-arg option' do
185
- let(:args) { ['--no-parentheses-matcher-arg'] }
186
-
187
- before do
188
- parser.stub(:warn)
189
- end
190
-
191
- it 'sets Config#parenthesize_matcher_arg? false' do
192
- parser.parse(args)
193
- config.parenthesize_matcher_arg.should be_false
194
- end
195
-
196
- it 'is deprecated' do
197
- parser.should_receive(:warn) do |message|
198
- message.should =~ /--no-parentheses-matcher-arg.+deprecated/i
199
- end
200
-
201
- parser.parse(args)
202
- end
203
- end
204
-
205
- describe '--no-color option' do
206
- before do
207
- Rainbow.enabled = true
208
- end
209
-
210
- let(:args) { ['--no-color'] }
211
-
212
- it 'disables color in the output' do
213
- parser.parse(args)
214
- Rainbow.enabled.should be_false
215
- end
216
- end
217
-
218
- describe '--version option' do
219
- before do
220
- parser.stub(:puts)
221
- parser.stub(:exit)
222
- end
223
-
224
- let(:args) { ['--version'] }
225
-
226
- it 'shows version' do
227
- parser.should_receive(:puts).with(Version.to_s)
228
- parser.parse(args)
229
- end
230
-
231
- it 'exits' do
232
- parser.should_receive(:exit)
233
- parser.parse(args)
234
- end
235
- end
236
- end
237
-
238
- describe 'help text' do
239
- subject(:help_text) do
240
- parser.help
241
- end
242
-
243
- it 'does not exceed 100 characters in each line' do
244
- help_text.each_line do |line|
245
- line.chomp.length.should <= 100
246
- end
247
- end
248
-
249
- def description_for_option(option)
250
- description_lines = parser.send(:descriptions)[option]
251
- description_lines.map { |line| parser.send(:highlight_text, line) }
252
- end
253
-
254
- def conversion_types_for_option(option)
255
- section = description_for_option(option)
256
-
257
- section.each_with_object([]) do |line, types|
258
- match = line.match(/^[ ]{2}([a-z_]+)/)
259
- next unless match
260
- types << match.captures.first
261
- end
262
- end
263
-
264
- it 'describes all conversion types for -k/--keep option' do
265
- conversion_types = conversion_types_for_option('-k')
266
- conversion_types.should =~ OptionParser::CONFIG_ATTRS_FOR_KEEP_TYPES.keys.map(&:to_s)
267
- end
268
-
269
- it 'describes all conversion types for -v/--convert option' do
270
- conversion_types = conversion_types_for_option('-v')
271
- conversion_types.should =~ OptionParser::CONFIG_ATTRS_FOR_CONVERT_TYPES.keys.map(&:to_s)
272
- end
273
- end
274
- end
275
- end
@@ -1,93 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'transpec/processed_source'
5
-
6
- module Transpec
7
- describe ProcessedSource do
8
- describe '.parse_file' do
9
- include FileHelper
10
- include_context 'isolated environment'
11
-
12
- let(:spec_path) { 'spec/example_spec.rb' }
13
-
14
- before do
15
- create_file(spec_path, "puts 'foo'")
16
- end
17
-
18
- it 'parses the file and returns processed source' do
19
- processed_source = ProcessedSource.from_file(spec_path)
20
- processed_source.path.should == spec_path
21
- processed_source.ast.should_not be_nil
22
- end
23
- end
24
-
25
- subject(:processed_source) { ProcessedSource.new(source) }
26
-
27
- describe '#ast' do
28
- let(:source) { "puts 'foo'" }
29
-
30
- it 'returns the root node of AST' do
31
- processed_source.ast.should be_a(Parser::AST::Node)
32
- end
33
- end
34
-
35
- describe '#path' do
36
- let(:source) { "puts 'foo'" }
37
-
38
- context 'when a file path is passed to .new' do
39
- subject(:processed_source) { ProcessedSource.new(source, '/path/to/file') }
40
-
41
- it 'returns the path' do
42
- processed_source.path.should == '/path/to/file'
43
- end
44
- end
45
-
46
- context 'when no file path is passed to .new' do
47
- it 'returns nil' do
48
- processed_source.path.should be_nil
49
- end
50
- end
51
- end
52
-
53
- describe '#syntax_error' do
54
- context 'when the source is valid' do
55
- let(:source) { "puts 'foo'" }
56
-
57
- it 'returns nil' do
58
- processed_source.error.should be_nil
59
- end
60
- end
61
-
62
- context 'when the source is invalid' do
63
- let(:source) { '<' }
64
-
65
- it 'returns syntax error' do
66
- processed_source.error.should be_a(Parser::SyntaxError)
67
- end
68
- end
69
-
70
- context 'when the source includes invalid byte sequence for the encoding' do
71
- it 'returns encoding error' do
72
- processed_source = ProcessedSource.new(<<-END)
73
- # coding: utf-8
74
- \xff
75
- END
76
- processed_source.error.should be_a(EncodingError)
77
- end
78
- end
79
- end
80
-
81
- describe '#to_s' do
82
- it 'returns the original source' do
83
- source = [
84
- "puts 'foo'",
85
- "puts 'bar'"
86
- ].join("\n")
87
-
88
- processed_source = ProcessedSource.new(source)
89
- processed_source.to_s.should == source
90
- end
91
- end
92
- end
93
- end