transpec 1.12.0 → 1.13.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 +103 -99
- data/README.md +52 -8
- data/README.md.erb +240 -95
- data/Rakefile +3 -1
- data/lib/transpec/base_rewriter.rb +1 -1
- data/lib/transpec/cli.rb +2 -1
- data/lib/transpec/converter.rb +9 -65
- data/lib/transpec/spec_suite.rb +3 -36
- data/lib/transpec/syntax.rb +61 -4
- data/lib/transpec/util.rb +0 -6
- data/lib/transpec/version.rb +1 -1
- data/spec/transpec/cli_spec.rb +6 -11
- data/spec/transpec/converter_spec.rb +0 -173
- data/spec/transpec/dynamic_analyzer_spec.rb +1 -1
- data/spec/transpec/record_spec.rb +15 -0
- data/spec/transpec_spec.rb +8 -0
- data/tasks/lib/test.rb +1 -0
- data/tasks/readme.rake +115 -46
- data/tasks/test.rake +2 -6
- metadata +3 -2
@@ -27,7 +27,7 @@ module Transpec
|
|
27
27
|
|
28
28
|
it 'changes working directory to copied project directory' do
|
29
29
|
initial_directory = Dir.pwd
|
30
|
-
DynamicAnalyzer.new(silent: true) do
|
30
|
+
DynamicAnalyzer.new(silent: true) do
|
31
31
|
Dir.pwd.should_not == initial_directory
|
32
32
|
end
|
33
33
|
end
|
@@ -9,6 +9,21 @@ module Transpec
|
|
9
9
|
let(:original_syntax) { 'obj.should' }
|
10
10
|
let(:converted_syntax) { 'expect(obj).to' }
|
11
11
|
|
12
|
+
[
|
13
|
+
:original_syntax,
|
14
|
+
:original_syntax_type,
|
15
|
+
:converted_syntax,
|
16
|
+
:converted_syntax_type
|
17
|
+
].each do |method|
|
18
|
+
it "forbids override of ##{method}" do
|
19
|
+
lambda do
|
20
|
+
Class.new(Record) do
|
21
|
+
define_method(method) {}
|
22
|
+
end
|
23
|
+
end.should raise_error(/override/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
12
27
|
describe '#to_s' do
|
13
28
|
it 'returns "`original syntax` -> `converted syntax`"' do
|
14
29
|
report.to_s.should == '`obj.should` -> `expect(obj).to`'
|
data/spec/transpec_spec.rb
CHANGED
@@ -4,6 +4,14 @@ require 'spec_helper'
|
|
4
4
|
require 'transpec'
|
5
5
|
|
6
6
|
module Transpec
|
7
|
+
describe '.root' do
|
8
|
+
it 'returns the path for project root directory' do
|
9
|
+
Dir.chdir(Transpec.root) do
|
10
|
+
File.should exist('Gemfile')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
describe '.required_rspec_version' do
|
8
16
|
subject { Transpec.required_rspec_version }
|
9
17
|
|
data/tasks/lib/test.rb
CHANGED
data/tasks/readme.rake
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
|
3
3
|
desc 'Generate README.md'
|
4
4
|
task :readme do
|
5
|
+
puts 'Generating README.md...'
|
5
6
|
File.write('README.md', generate_readme)
|
7
|
+
puts 'Done.'
|
6
8
|
end
|
7
9
|
|
8
10
|
namespace :readme do
|
9
11
|
task :check do
|
12
|
+
puts 'Checking README.md...'
|
13
|
+
|
10
14
|
unless File.read('README.md') == generate_readme
|
11
15
|
fail <<-END.gsub(/^\s+\|/, '').chomp
|
12
16
|
|README.md and README.md.erb are out of sync!
|
@@ -16,77 +20,142 @@ namespace :readme do
|
|
16
20
|
| * Commit both files.
|
17
21
|
END
|
18
22
|
end
|
23
|
+
|
24
|
+
puts 'Done.'
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
22
28
|
def generate_readme
|
23
29
|
require 'erb'
|
24
|
-
require 'transpec/cli'
|
25
|
-
|
26
30
|
readme = File.read('README.md.erb')
|
27
31
|
erb = ERB.new(readme, nil, '-')
|
28
|
-
erb.result(binding)
|
32
|
+
erb.result(READMEContext.new(readme).binding)
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
class READMEContext
|
36
|
+
attr_reader :readme
|
37
|
+
|
38
|
+
def initialize(readme)
|
39
|
+
@readme = readme
|
40
|
+
require 'transpec'
|
41
|
+
require 'transpec/cli'
|
42
|
+
require 'stringio'
|
43
|
+
require 'tmpdir'
|
44
|
+
require 'rspec/mocks/standalone'
|
45
|
+
require File.join(Transpec.root, 'spec/support/file_helper')
|
46
|
+
end
|
36
47
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
48
|
+
def binding
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def convert(source, options = {}) # rubocop:disable MethodLength
|
53
|
+
cli = Transpec::CLI.new
|
54
|
+
cli.project.stub(:rspec_version).and_return(options[:rspec_version]) if options[:rspec_version]
|
40
55
|
|
41
|
-
|
42
|
-
|
43
|
-
|
56
|
+
cli_args = Array(options[:cli])
|
57
|
+
cli_args << '--skip-dynamic-analysis' unless options[:dynamic] # For performance
|
58
|
+
|
59
|
+
hidden_code = options[:hidden]
|
60
|
+
if hidden_code
|
61
|
+
hidden_code += "\n"
|
62
|
+
source = hidden_code + source
|
63
|
+
end
|
64
|
+
|
65
|
+
source = wrap_source(source, options[:wrap_with])
|
66
|
+
|
67
|
+
converted_source = nil
|
68
|
+
|
69
|
+
in_isolated_env do
|
70
|
+
FileHelper.create_file('spec/example_spec.rb', source)
|
71
|
+
cli.run(cli_args)
|
72
|
+
converted_source = File.read('spec/example_spec.rb')
|
73
|
+
end
|
74
|
+
|
75
|
+
converted_source = unwrap_source(converted_source, options[:wrap_with])
|
76
|
+
converted_source = converted_source[hidden_code.length..-1] if hidden_code
|
77
|
+
converted_source
|
44
78
|
end
|
45
|
-
end
|
46
79
|
|
47
|
-
def
|
48
|
-
|
80
|
+
def wrap_source(source, wrapper)
|
81
|
+
source = "it 'is example' do\n" + source + "end\n" if wrapper == :example
|
49
82
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end.compact
|
83
|
+
if [:example, :group].include?(wrapper)
|
84
|
+
source = "describe 'example group' do\n" + source + "end\n"
|
85
|
+
end
|
54
86
|
|
55
|
-
|
56
|
-
|
57
|
-
"* [#{title}](#{anchor})"
|
58
|
-
end.join("\n")
|
59
|
-
end
|
87
|
+
source
|
88
|
+
end
|
60
89
|
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
90
|
+
def unwrap_source(source, wrapper)
|
91
|
+
return source unless wrapper
|
64
92
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end.sort
|
93
|
+
unwrap_count = case wrapper
|
94
|
+
when :group then 1
|
95
|
+
when :example then 2
|
96
|
+
end
|
70
97
|
|
71
|
-
|
98
|
+
lines = source.lines.to_a
|
72
99
|
|
73
|
-
|
74
|
-
|
75
|
-
|
100
|
+
unwrap_count.times do
|
101
|
+
lines = lines[1..-2]
|
102
|
+
end
|
103
|
+
|
104
|
+
lines.join('')
|
76
105
|
end
|
77
|
-
end
|
78
106
|
|
79
|
-
|
107
|
+
def in_isolated_env
|
108
|
+
original_stdout = $stdout
|
109
|
+
$stdout = StringIO.new
|
80
110
|
|
81
|
-
|
82
|
-
|
111
|
+
Dir.mktmpdir do |tmpdir|
|
112
|
+
Dir.chdir(tmpdir) do
|
113
|
+
yield
|
114
|
+
end
|
115
|
+
end
|
116
|
+
ensure
|
117
|
+
$stdout = original_stdout
|
83
118
|
end
|
84
119
|
|
85
|
-
def
|
86
|
-
|
120
|
+
def select_sections(content, header_level, *section_names)
|
121
|
+
header_pattern = pattern_for_header_level(header_level)
|
122
|
+
sections = content.each_line.slice_before(header_pattern)
|
123
|
+
|
124
|
+
sections.select do |section|
|
125
|
+
header_line = section.first
|
126
|
+
section_names.any? { |name| header_line.include?(name) }
|
127
|
+
end
|
87
128
|
end
|
88
129
|
|
89
|
-
def
|
90
|
-
|
130
|
+
def table_of_contents(lines, header_level)
|
131
|
+
header_pattern = pattern_for_header_level(header_level)
|
132
|
+
|
133
|
+
titles = lines.map do |line|
|
134
|
+
next unless line.match(header_pattern)
|
135
|
+
line.sub(/^[#\s]*/, '').chomp
|
136
|
+
end.compact
|
137
|
+
|
138
|
+
titles.map do |title|
|
139
|
+
anchor = '#' + title.gsub(/[^\w_\- ]/, '').downcase.gsub(' ', '-')
|
140
|
+
"* [#{title}](#{anchor})"
|
141
|
+
end.join("\n")
|
142
|
+
end
|
143
|
+
|
144
|
+
def pattern_for_header_level(level)
|
145
|
+
/^#{'#' * level}[^#]/
|
146
|
+
end
|
147
|
+
|
148
|
+
def validate_syntax_type_table(markdown_table, types_in_code)
|
149
|
+
types_in_doc = markdown_table.lines.map do |line|
|
150
|
+
first_column = line.split('|').first
|
151
|
+
first_column.gsub(/[^\w]/, '').to_sym
|
152
|
+
end.sort
|
153
|
+
|
154
|
+
types_in_code.sort!
|
155
|
+
|
156
|
+
unless types_in_doc == types_in_code
|
157
|
+
types_missing_description = types_in_code - types_in_doc
|
158
|
+
fail "No descriptions for syntax types #{types_missing_description}"
|
159
|
+
end
|
91
160
|
end
|
92
161
|
end
|
data/tasks/test.rake
CHANGED
@@ -14,13 +14,9 @@ namespace :test do
|
|
14
14
|
tests = [
|
15
15
|
Test.new(Transpec.root, nil, ['--quiet'], true),
|
16
16
|
Test.new('https://github.com/yujinakayama/twitter.git', 'transpec-test-rspec-2-99', bundler_args),
|
17
|
-
Test.new('https://github.com/yujinakayama/mail.git', 'transpec-test-rspec-2-99', bundler_args)
|
17
|
+
Test.new('https://github.com/yujinakayama/mail.git', 'transpec-test-rspec-2-99', bundler_args),
|
18
|
+
# Test.new('https://github.com/yujinakayama/guard.git', 'transpec-test-rspec-2-99', bundler_args + %w(--without development))
|
18
19
|
]
|
19
|
-
|
20
|
-
# Sometimes Guard fails with JRuby randomly.
|
21
|
-
unless RUBY_ENGINE == 'jruby'
|
22
|
-
tests << Test.new('https://github.com/yujinakayama/guard.git', 'transpec-test-rspec-2-99', bundler_args + %w(--without development))
|
23
|
-
end
|
24
20
|
# rubocop:enable LineLength
|
25
21
|
|
26
22
|
desc 'Test transpec on all projects'
|
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.
|
4
|
+
version: 1.13.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-04-
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -448,3 +448,4 @@ test_files:
|
|
448
448
|
- spec/transpec/syntax/should_spec.rb
|
449
449
|
- spec/transpec/util_spec.rb
|
450
450
|
- spec/transpec_spec.rb
|
451
|
+
has_rdoc:
|