transpec 3.0.0 → 3.0.1

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.
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,74 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'transpec/directory_cloner'
5
-
6
- module Transpec
7
- describe DirectoryCloner do
8
- include FileHelper
9
- include_context 'isolated environment'
10
-
11
- describe '#copy_recursively' do
12
- it 'copies files recursively' do
13
- [
14
- 'src/file1',
15
- 'src/file2',
16
- 'src/dir1/file',
17
- 'src/dir2/file'
18
- ].each do |path|
19
- create_file(path, '')
20
- end
21
-
22
- DirectoryCloner.copy_recursively('src', 'dst')
23
-
24
- [
25
- 'dst/file1',
26
- 'dst/file2',
27
- 'dst/dir1/file',
28
- 'dst/dir2/file'
29
- ].each do |path|
30
- File.exist?(path).should be_true
31
- end
32
- end
33
-
34
- it 'copies only directories, files and symlinks' do
35
- create_file('src/file', '')
36
- File.symlink('file', 'src/symlink')
37
- Dir.mkdir('src/dir')
38
- system('mkfifo', 'src/fifo')
39
-
40
- DirectoryCloner.copy_recursively('src', 'dst')
41
-
42
- File.file?('dst/file').should be_true
43
- File.symlink?('dst/symlink').should be_true
44
- File.directory?('dst/dir').should be_true
45
- File.exist?('dst/fifo').should be_false
46
- end
47
-
48
- def permission(path)
49
- format('%o', File.lstat(path).mode)[-4..-1]
50
- end
51
-
52
- it 'preserves permission' do
53
- create_file('src/file', '')
54
- File.chmod(0755, 'src/file')
55
-
56
- File.symlink('file', 'src/symlink')
57
-
58
- Dir.mkdir('src/dir')
59
- File.chmod(0600, 'src/dir')
60
-
61
- DirectoryCloner.copy_recursively('src', 'dst')
62
-
63
- permission('dst/file').should == '0755'
64
- permission('dst/dir').should == '0600'
65
- end
66
-
67
- it 'returns the copied directory path' do
68
- Dir.mkdir('src')
69
- path = DirectoryCloner.copy_recursively('src', 'dst')
70
- path.should == File.expand_path('dst')
71
- end
72
- end
73
- end
74
- end
@@ -1,143 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'transpec/dynamic_analyzer/rewriter'
5
-
6
- module Transpec
7
- class DynamicAnalyzer
8
- describe Rewriter do
9
- include ::AST::Sexp
10
-
11
- subject(:rewriter) { Rewriter.new }
12
-
13
- describe '#rewrite_source' do
14
- subject { rewriter.rewrite_source(source) }
15
-
16
- let(:source) do
17
- <<-END
18
- subject.should be(foo)
19
- END
20
- end
21
-
22
- # rubocop:disable LineLength
23
- let(:expected_source) do
24
- <<-'END'
25
- Transpec.analyze((Transpec.analyze((subject), self, "(string)_12_19", { :should_source_location => [:object, "method(:should).source_location"], :should_example_method_defined_by_user? => [:object, "owner = method(:should).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).should be(foo)), self, "(string)_12_34", { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"] })
26
- END
27
- end
28
- # rubocop:enable LineLength
29
-
30
- it 'wraps target object with analysis helper method' do
31
- should == expected_source
32
- end
33
-
34
- context 'when the target includes here document' do
35
- let(:source) do
36
- <<-END
37
- subject.should =~ <<-HEREDOC.gsub('foo', 'bar')
38
- foo
39
- HEREDOC
40
- END
41
- end
42
-
43
- # rubocop:disable LineLength
44
- let(:expected_source) do
45
- <<-'END'
46
- Transpec.analyze((Transpec.analyze((subject), self, "(string)_14_21", { :should_source_location => [:object, "method(:should).source_location"], :should_example_method_defined_by_user? => [:object, "owner = method(:should).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).should), self, "(string)_14_28", { :expect_available? => [:context, "self.class.ancestors.any? { |a| a.name.start_with?('RSpec::') } && respond_to?(:expect)"], :"=~_source_location" => [:object, "method(:=~).source_location"], :"=~_example_method_defined_by_user?" => [:object, "owner = method(:=~).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }) =~ Transpec.analyze((<<-HEREDOC.gsub('foo', 'bar')), self, "(string)_32_61", { :enumerable_arg? => [:object, "is_a?(Enumerable)"] })
47
- foo
48
- HEREDOC
49
- END
50
- end
51
- # rubocop:enable LineLength
52
-
53
- it 'wraps the here document properly' do
54
- should == expected_source
55
- end
56
- end
57
-
58
- context 'when the target takes block' do
59
- let(:source) do
60
- <<-END
61
- expect { do_something }.to throw_symbol
62
- END
63
- end
64
-
65
- # rubocop:disable LineLength
66
- let(:expected_source) do
67
- <<-'END'
68
- Transpec.analyze((expect { do_something }), self, "(string)_14_20", { :expect_source_location => [:context, "method(:expect).source_location"], :expect_example_method_defined_by_user? => [:context, "owner = method(:expect).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] }).to throw_symbol
69
- END
70
- end
71
- # rubocop:enable LineLength
72
-
73
- it 'wraps the block properly' do
74
- should == expected_source
75
- end
76
- end
77
-
78
- context 'when the target is method invocation without parentheses' do
79
- let(:source) do
80
- <<-END
81
- double 'something'
82
- END
83
- end
84
-
85
- # rubocop:disable LineLength
86
- let(:expected_source) do
87
- <<-'END'
88
- Transpec.analyze((double 'something'), self, "(string)_14_32", { :double_source_location => [:context, "method(:double).source_location"], :double_example_method_defined_by_user? => [:context, "owner = method(:double).owner\nowner != RSpec::Core::ExampleGroup &&\n owner.ancestors.include?(RSpec::Core::ExampleGroup)"] })
89
- END
90
- end
91
- # rubocop:enable LineLength
92
-
93
- it 'wraps the target properly' do
94
- should == expected_source
95
- end
96
- end
97
- end
98
-
99
- describe '#register_request' do
100
- include_context 'parsed objects'
101
-
102
- let(:source) do
103
- <<-END
104
- 1
105
- 2
106
- END
107
- end
108
-
109
- let(:a_node) { ast.children[0] }
110
- let(:another_node) { ast.children[1] }
111
-
112
- it 'stores requests for each node' do
113
- rewriter.register_request(a_node, :odd, 'odd?', :object)
114
- rewriter.register_request(another_node, :even, 'even?', :object)
115
- rewriter.requests[a_node].should == { odd: [:object, 'odd?'] }
116
- rewriter.requests[another_node].should == { even: [:object, 'even?'] }
117
- end
118
-
119
- it 'merges multiple requests for same node' do
120
- rewriter.register_request(a_node, :odd, 'odd?', :object)
121
- rewriter.register_request(a_node, :even, 'even?', :object)
122
- rewriter.requests[a_node].should == { odd: [:object, 'odd?'], even: [:object, 'even?'] }
123
- end
124
-
125
- context 'when there are same structure nodes but they are not identical objects' do
126
- let(:source) do
127
- <<-END
128
- 1
129
- 1
130
- END
131
- end
132
-
133
- it 'properly diffrenciate them' do
134
- rewriter.register_request(a_node, :odd, 'odd?', :object)
135
- rewriter.register_request(another_node, :even, 'even?', :object)
136
- rewriter.requests[a_node].should == { odd: [:object, 'odd?'] }
137
- rewriter.requests[another_node].should == { even: [:object, 'even?'] }
138
- end
139
- end
140
- end
141
- end
142
- end
143
- end
@@ -1,329 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'transpec/dynamic_analyzer'
5
-
6
- module Transpec
7
- describe DynamicAnalyzer do
8
- include FileHelper
9
- include ::AST::Sexp
10
- include_context 'isolated environment'
11
-
12
- def find_node_in_file(file_path, &block)
13
- processed_source = ProcessedSource.from_file(file_path)
14
- processed_source.ast.each_node.find(&block)
15
- end
16
-
17
- subject(:dynamic_analyzer) { DynamicAnalyzer.new(rspec_command: rspec_command, silent: true) }
18
- let(:rspec_command) { nil }
19
-
20
- describe '.new' do
21
- context 'when block is passed' do
22
- it 'yields the instance' do
23
- yielded = false
24
-
25
- DynamicAnalyzer.new(silent: true) do |analyzer|
26
- yielded = true
27
- analyzer.should be_a(DynamicAnalyzer)
28
- end
29
-
30
- yielded.should be_true
31
- end
32
-
33
- it 'changes working directory to copied project directory' do
34
- initial_directory = Dir.pwd
35
- DynamicAnalyzer.new(silent: true) do
36
- Dir.pwd.should_not == initial_directory
37
- end
38
- end
39
- end
40
- end
41
-
42
- describe '#rspec_command' do
43
- subject { dynamic_analyzer.rspec_command }
44
-
45
- context 'when command is specified' do
46
- let(:rspec_command) { 'rspec some_argument' }
47
-
48
- it 'returns the specified command' do
49
- should == rspec_command
50
- end
51
- end
52
-
53
- context 'when command is not specified' do
54
- context 'and there is a Gemfile.lock' do
55
- before do
56
- create_file('Gemfile.lock', '')
57
- end
58
-
59
- it 'returns "bundle exec rspec"' do
60
- should == 'bundle exec rspec'
61
- end
62
- end
63
-
64
- context 'and there is no Gemfile.lock' do
65
- it 'returns "rspec"' do
66
- should == 'rspec'
67
- end
68
- end
69
- end
70
- end
71
-
72
- describe '#analyze' do
73
- before do
74
- create_file(spec_file_path, source)
75
- end
76
-
77
- let(:spec_file_path) { 'spec/example_spec.rb' }
78
-
79
- let(:source) do
80
- <<-END
81
- describe [1, 2] do
82
- it 'has 2 items' do
83
- expect(subject).to have(2).items
84
- end
85
- end
86
- END
87
- end
88
-
89
- context 'when already in copied project directory' do
90
- it 'does not copy the project again' do
91
- DynamicAnalyzer.new(silent: true) do |analyzer|
92
- DirectoryCloner.should_not_receive(:copy_recursively)
93
- analyzer.analyze
94
- end
95
- end
96
- end
97
-
98
- context 'when no path is passed' do
99
- it 'rewrites all files in the "spec" directory' do
100
- DynamicAnalyzer::Rewriter.any_instance.should_receive(:rewrite_file!) do |spec|
101
- spec.path.should == spec_file_path
102
- end
103
-
104
- dynamic_analyzer.analyze
105
- end
106
- end
107
-
108
- context 'when some paths are passed' do
109
- before do
110
- create_file('spec/another_spec.rb', '')
111
- end
112
-
113
- it 'rewrites only files in the passed paths' do
114
- DynamicAnalyzer::Rewriter.any_instance.should_receive(:rewrite_file!) do |spec|
115
- spec.path.should == spec_file_path
116
- end
117
-
118
- dynamic_analyzer.analyze([spec_file_path])
119
- end
120
- end
121
-
122
- context 'when there is invalid syntax source file' do
123
- before do
124
- create_file('spec/fixtures/invalid.rb', 'This is invalid syntax <')
125
- end
126
-
127
- it 'does not raise error' do
128
- -> { dynamic_analyzer.analyze }.should_not raise_error
129
- end
130
- end
131
-
132
- context 'when rspec did not pass' do
133
- let(:source) do
134
- <<-END
135
- describe [1, 2] do
136
- it 'has 2 items' do
137
- expect(subject).to have(1).items
138
- end
139
- end
140
- END
141
- end
142
-
143
- it 'does not raise error' do
144
- -> { dynamic_analyzer.analyze }.should_not raise_error
145
- end
146
- end
147
-
148
- context 'when analysis result data file is not found' do
149
- let(:source) { 'exit!' }
150
-
151
- it 'raises AnalysisError' do
152
- -> { dynamic_analyzer.analyze }
153
- .should raise_error(DynamicAnalyzer::AnalysisError, /Failed running dynamic analysis/)
154
- end
155
- end
156
-
157
- context 'when working directory has been changed at exit of rspec' do
158
- let(:source) { "Dir.chdir('spec')" }
159
-
160
- it 'does not raise error' do
161
- -> { dynamic_analyzer.analyze }.should_not raise_error
162
- end
163
- end
164
-
165
- context 'when rspec is run via rake task' do
166
- before do
167
- create_file('Rakefile', <<-END)
168
- require 'rspec/core/rake_task'
169
- RSpec::Core::RakeTask.new(:spec)
170
- END
171
- end
172
-
173
- let(:rspec_command) { 'rake spec' }
174
-
175
- it 'does not raise error' do
176
- -> { dynamic_analyzer.analyze }.should_not raise_error
177
- end
178
- end
179
-
180
- context 'when there is a .rspec file containing `--require spec_helper`' do
181
- before do
182
- create_file('.rspec', '--require spec_helper')
183
- end
184
-
185
- context 'and the spec/spec_helper.rb contains some code that is dynamic analysis target' do
186
- before do
187
- create_file('spec/spec_helper.rb', <<-END)
188
- RSpec.configure { }
189
-
190
- def some_helper_method_used_in_each_spec
191
- end
192
- END
193
- end
194
-
195
- let(:source) do
196
- <<-END
197
- some_helper_method_used_in_each_spec
198
-
199
- describe 'something' do
200
- end
201
- END
202
- end
203
-
204
- it 'does not raise error' do
205
- -> { dynamic_analyzer.analyze }.should_not raise_error
206
- end
207
-
208
- it 'preserves the existing `--require`' do
209
- describe_node = find_node_in_file(spec_file_path) do |node|
210
- node.send_type? && node.children[1] == :describe
211
- end
212
-
213
- runtime_data = dynamic_analyzer.analyze
214
- runtime_data.run?(describe_node).should be_true
215
- end
216
- end
217
- end
218
-
219
- context 'when there is a proxy/delegator Class that undefines Object methods' do
220
- let(:source) do
221
- # https://github.com/thoughtbot/factory_girl/blob/v4.4.0/lib/factory_girl/definition_proxy.rb#L3-L7
222
- <<-END
223
- class SomeProxy
224
- UNPROXIED_METHODS = %w(__send__ object_id initialize instance_eval).map(&:to_sym)
225
-
226
- (instance_methods + private_instance_methods).each do |method|
227
- undef_method(method) unless UNPROXIED_METHODS.include?(method)
228
- end
229
- end
230
-
231
- describe 'example' do
232
- it 'is 1' do
233
- proxy = SomeProxy.new
234
- proxy.instance_eval do
235
- 1.should == 1
236
- end
237
- end
238
- end
239
- END
240
- end
241
-
242
- it 'properly analyzes even in such context' do
243
- should_node = find_node_in_file(spec_file_path) do |node|
244
- node.send_type? && node.children[1] == :should
245
- end
246
-
247
- runtime_data = dynamic_analyzer.analyze
248
- runtime_data.run?(should_node).should be_true
249
- end
250
- end
251
-
252
- context 'when a deprecated syntax is used with `RSpec.configure { |c| c.raise_errors_for_deprecations! }`' do
253
- include CacheHelper
254
-
255
- around do |example|
256
- with_cached_dir('rspec-2.99-project') do |cached|
257
- unless cached
258
- create_file('Gemfile', <<-END)
259
- source 'https://rubygems.org'
260
- gem 'rspec', '~> 2.99'
261
- END
262
-
263
- Bundler.with_clean_env do
264
- `bundle install --path vendor/bundle`
265
- end
266
-
267
- create_file('spec/spec_helper.rb', <<-END)
268
- RSpec.configure do |config|
269
- config.raise_errors_for_deprecations!
270
- end
271
- END
272
- end
273
-
274
- example.run
275
- end
276
- end
277
-
278
- let(:source) do
279
- <<-END
280
- require 'spec_helper'
281
-
282
- describe 'example' do
283
- it 'is deprecated syntax' do
284
- mock('something')
285
- end
286
- end
287
- END
288
- end
289
-
290
- it 'raises AnalysisError with a warning message about `raise_errors_for_deprecations!`' do
291
- -> { dynamic_analyzer.analyze }
292
- .should raise_error(DynamicAnalyzer::AnalysisError, /raise_errors_for_deprecations!/)
293
- end
294
- end
295
-
296
- runtime_data_cache = {}
297
-
298
- subject(:runtime_data) do
299
- if runtime_data_cache[source]
300
- runtime_data_cache[source]
301
- else
302
- runtime_data_cache[source] = dynamic_analyzer.analyze
303
- end
304
- end
305
-
306
- it 'returns an instance of DynamicAnalyzer::RuntimeData' do
307
- runtime_data.should be_an(DynamicAnalyzer::RuntimeData)
308
- end
309
-
310
- describe 'an element of the runtime data' do
311
- let(:target_node) do
312
- find_node_in_file(spec_file_path) do |node|
313
- node == s(:send, nil, :subject)
314
- end
315
- end
316
-
317
- subject(:element) { runtime_data[target_node] }
318
-
319
- it 'is an OpenStruct' do
320
- should be_a(OpenStruct)
321
- end
322
-
323
- it 'has result of requested analysis' do
324
- element[:available_query_methods].should =~ %w(size count length)
325
- end
326
- end
327
- end
328
- end
329
- end