transpec 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 |analyzer|
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`'
@@ -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
@@ -25,6 +25,7 @@ class Test < Project
25
25
  return if simple?
26
26
  compare_summary!('2.99.0')
27
27
 
28
+ puts 'Rewriting `rspec` version in Gemfile as 3.0.0'
28
29
  add_rspec_3_to_gemfile
29
30
  sh 'bundle update'
30
31
 
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
- def convert(source, configuration = nil, rspec_version = nil)
32
- spec_suite = FakeSpecSuite.new
33
- converter = Transpec::Converter.new(spec_suite, configuration, rspec_version)
34
- converter.convert_source(source)
35
- end
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 select_sections(content, header_level, *section_names)
38
- header_pattern = pattern_for_header_level(header_level)
39
- sections = content.each_line.slice_before(header_pattern)
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
- sections.select do |section|
42
- header_line = section.first
43
- section_names.any? { |name| header_line.include?(name) }
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 table_of_contents(lines, header_level)
48
- header_pattern = pattern_for_header_level(header_level)
80
+ def wrap_source(source, wrapper)
81
+ source = "it 'is example' do\n" + source + "end\n" if wrapper == :example
49
82
 
50
- titles = lines.map do |line|
51
- next unless line.match(header_pattern)
52
- line.sub(/^[#\s]*/, '').chomp
53
- end.compact
83
+ if [:example, :group].include?(wrapper)
84
+ source = "describe 'example group' do\n" + source + "end\n"
85
+ end
54
86
 
55
- titles.map do |title|
56
- anchor = '#' + title.gsub(/[^\w_\- ]/, '').downcase.gsub(' ', '-')
57
- "* [#{title}](#{anchor})"
58
- end.join("\n")
59
- end
87
+ source
88
+ end
60
89
 
61
- def pattern_for_header_level(level)
62
- /^#{'#' * level}[^#]/
63
- end
90
+ def unwrap_source(source, wrapper)
91
+ return source unless wrapper
64
92
 
65
- def validate_syntax_type_table(markdown_table, types_in_code)
66
- types_in_doc = markdown_table.lines.map do |line|
67
- first_column = line.split('|').first
68
- first_column.gsub(/[^\w]/, '').to_sym
69
- end.sort
93
+ unwrap_count = case wrapper
94
+ when :group then 1
95
+ when :example then 2
96
+ end
70
97
 
71
- types_in_code.sort!
98
+ lines = source.lines.to_a
72
99
 
73
- unless types_in_doc == types_in_code
74
- types_missing_description = types_in_code - types_in_doc
75
- fail "No descriptions for syntax types #{types_missing_description}"
100
+ unwrap_count.times do
101
+ lines = lines[1..-2]
102
+ end
103
+
104
+ lines.join('')
76
105
  end
77
- end
78
106
 
79
- require 'transpec/spec_suite'
107
+ def in_isolated_env
108
+ original_stdout = $stdout
109
+ $stdout = StringIO.new
80
110
 
81
- class FakeSpecSuite < Transpec::SpecSuite
82
- def analyze
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 need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
86
- true
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 main_rspec_configure_node?(node)
90
- true
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.12.0
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-07 00:00:00.000000000 Z
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: