rspec-kickstarter 0.2.7 → 0.3.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.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require "rspec_kickstarter/generator"
4
- require "rspec_kickstarter/version"
3
+ require 'rspec_kickstarter/generator'
4
+ require 'rspec_kickstarter/version'
5
5
 
6
6
  #
7
7
  # RSpecKickstarter Facade
@@ -17,14 +17,16 @@ class RSpecKickstarter::ERBFactory
17
17
  # Returns ERB instance for creating new spec
18
18
  #
19
19
  def get_instance_for_new_spec(rails_mode, target_path)
20
- ERB.new(get_erb_template(@custom_template, true, rails_mode, target_path), nil, '-', '_new_spec_code')
20
+ template = get_erb_template(@custom_template, true, rails_mode, target_path)
21
+ ERB.new(template, nil, '-', '_new_spec_code')
21
22
  end
22
23
 
23
24
  #
24
25
  # Returns ERB instance for appeding lacking tests
25
26
  #
26
27
  def get_instance_for_appending(rails_mode, target_path)
27
- ERB.new(get_erb_template(@custom_template, false, rails_mode, target_path), nil, '-', '_additional_spec_code')
28
+ template = get_erb_template(@custom_template, false, rails_mode, target_path)
29
+ ERB.new(template, nil, '-', '_additional_spec_code')
28
30
  end
29
31
 
30
32
  private
@@ -36,15 +38,15 @@ class RSpecKickstarter::ERBFactory
36
38
  if custom_template
37
39
  custom_template
38
40
  elsif rails_mode && target_path.match(/controllers/)
39
- if is_full then RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
41
+ if is_full then RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
40
42
  else RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_METHODS_PART_TEMPLATE
41
43
  end
42
44
  elsif rails_mode && target_path.match(/helpers/)
43
- if is_full then RSpecKickstarter::ERBTemplates::RAILS_HELPER_NEW_SPEC_TEMPLATE
45
+ if is_full then RSpecKickstarter::ERBTemplates::RAILS_HELPER_NEW_SPEC_TEMPLATE
44
46
  else RSpecKickstarter::ERBTemplates::RAILS_HELPER_METHODS_PART_TEMPLATE
45
47
  end
46
48
  else
47
- if is_full then RSpecKickstarter::ERBTemplates::BASIC_NEW_SPEC_TEMPLATE
49
+ if is_full then RSpecKickstarter::ERBTemplates::BASIC_NEW_SPEC_TEMPLATE
48
50
  else RSpecKickstarter::ERBTemplates::BASIC_METHODS_PART_TEMPLATE
49
51
  end
50
52
  end
@@ -24,7 +24,7 @@ class RSpecKickstarter::Generator
24
24
  # Writes new spec or appends to the existing spec.
25
25
  #
26
26
  def write_spec(file_path, force_write = false, dry_run = false, rails_mode = false)
27
- class_or_module = RSpecKickstarter::RDocFactory::get_rdoc_class_or_module(file_path)
27
+ class_or_module = RSpecKickstarter::RDocFactory.get_rdoc_class_or_module(file_path)
28
28
  if class_or_module
29
29
  spec_path = get_spec_path(file_path)
30
30
  if force_write && File.exist?(spec_path)
@@ -53,7 +53,7 @@ class RSpecKickstarter::Generator
53
53
  # e.g. "lib/foo/bar_baz.rb" -> "spec/foo/bar_baz_spec.rb"
54
54
  #
55
55
  def get_spec_path(file_path)
56
- spec_dir + '/' + file_path.gsub(/^\.\//, '').gsub(/^(lib\/)|(app\/)/, '').gsub(/\.rb$/, '_spec.rb')
56
+ spec_dir + '/' + file_path.gsub(/^\.\//, '').gsub(%r{^(lib/)|(app/)}, '').gsub(/\.rb$/, '_spec.rb')
57
57
  end
58
58
 
59
59
  #
@@ -61,19 +61,19 @@ class RSpecKickstarter::Generator
61
61
  # e.g. "lib/foo/bar_baz.rb" -> "foo/bar_baz"
62
62
  #
63
63
  def to_string_value_to_require(file_path)
64
- file_path.gsub(/^(lib\/)|(app\/)/, '').gsub(/\.rb$/, '')
64
+ file_path.gsub(%r{^(lib/)|(app/)}, '').gsub(/\.rb$/, '')
65
65
  end
66
66
 
67
- #
67
+ #
68
68
  # Returns snake_case name.
69
69
  # e.g. FooBar -> "foo_bar"
70
70
  #
71
71
  def instance_name(c)
72
72
  c.name
73
73
  .gsub(/::/, '/')
74
- .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
75
- .gsub(/([a-z\d])([A-Z])/,'\1_\2')
76
- .tr("-", "_")
74
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
75
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
76
+ .tr('-', '_')
77
77
  .downcase
78
78
  end
79
79
 
@@ -93,7 +93,7 @@ class RSpecKickstarter::Generator
93
93
  #
94
94
  def to_params_part(params)
95
95
  param_csv = to_param_names_array(params).join(', ')
96
- param_csv.empty? ? "" : "(#{param_csv})"
96
+ param_csv.empty? ? '' : "(#{param_csv})"
97
97
  end
98
98
 
99
99
  #
@@ -141,15 +141,14 @@ class RSpecKickstarter::Generator
141
141
 
142
142
  erb = RSpecKickstarter::ERBFactory.new(@delta_template).get_instance_for_appending(rails_mode, spec_path)
143
143
  additional_spec = erb.result(binding)
144
+
144
145
  last_end_not_found = true
145
146
  code = existing_spec.split("\n").reverse.reject { |line|
146
- if last_end_not_found
147
- last_end_not_found = line.gsub(/#.+$/, '').strip != "end"
148
- true
149
- else
150
- false
151
- end
147
+ before_modified = last_end_not_found
148
+ last_end_not_found = line.gsub(/#.+$/, '').strip != 'end' if before_modified
149
+ before_modified
152
150
  }.reverse.join("\n") + "\n" + additional_spec + "\nend\n"
151
+
153
152
  if dry_run
154
153
  puts "----- #{spec_path} -----"
155
154
  puts code
@@ -166,13 +165,13 @@ class RSpecKickstarter::Generator
166
165
 
167
166
  #
168
167
  # e.g.
169
- # a = stub('a')
170
- # b = stub('b')
168
+ # a = double('a')
169
+ # b = double('b')
171
170
  # bar_baz = BarBaz.new(a, b)
172
171
  #
173
172
  def get_instantiation_code(c, method)
174
173
  if method.singleton
175
- ""
174
+ ''
176
175
  else
177
176
  constructor = c.method_list.find { |m| m.name == 'new' }
178
177
  if constructor.nil?
@@ -186,12 +185,12 @@ class RSpecKickstarter::Generator
186
185
 
187
186
  #
188
187
  # e.g.
189
- # a = stub('a')
190
- # b = stub('b')
188
+ # a = double('a')
189
+ # b = double('b')
191
190
  #
192
191
  def get_params_initialization_code(method)
193
- code = to_param_names_array(method.params).map { |p| " #{p} = stub('#{p}')" }.join("\n")
194
- code.empty? ? "" : "#{code}\n"
192
+ code = to_param_names_array(method.params).map { |p| " #{p} = double('#{p}')" }.join("\n")
193
+ code.empty? ? '' : "#{code}\n"
195
194
  end
196
195
 
197
196
  #
@@ -214,7 +213,7 @@ class RSpecKickstarter::Generator
214
213
  #
215
214
  def get_block_code(method)
216
215
  if method.block_params.nil? || method.block_params.empty?
217
- ""
216
+ ''
218
217
  else
219
218
  " { |#{method.block_params}| }"
220
219
  end
@@ -30,7 +30,7 @@ class RSpecKickstarter::RDocFactory
30
30
  top_level = RDoc::TopLevel.new(file_path)
31
31
  if RUBY_VERSION.to_f < 2.0
32
32
  # reset is removed since 2.0
33
- RDoc::TopLevel.reset()
33
+ RDoc::TopLevel.reset
34
34
  end
35
35
 
36
36
  # RDoc::Stats initialization
@@ -1,3 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Gem version
5
+ #
1
6
  module RSpecKickstarter
2
- VERSION = "0.2.7"
7
+ VERSION = '0.3.0'
3
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-kickstarter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-13 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: rspec-kickstarter supports you writing tests for existing code.
15
15
  email: