pretentious 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcb15b476f2169fe2872dd04836ca084b8af85f1
4
- data.tar.gz: bc78a261f3d94b73d91157e07a623143111a4d5c
3
+ metadata.gz: dd2bfc31ab30d31a3511324c22c48380a7daf813
4
+ data.tar.gz: af221ef98f7d0f5f4c321a7f795455d8c03cfbb4
5
5
  SHA512:
6
- metadata.gz: a717cd689858d75a0eb9567c0cfc7994793381e050c3b1025c8abe541955e847163c8187cb09a9a5458605e9e655e3a5cb1fc23ec1fad8771775bc20b521f357
7
- data.tar.gz: 8f3110582c6423b258b89fad1482071c416b500469892b0777837c4d97858e611526db475a1c242e2ef35478dd299db2a9ce511a15a1e71853be04b08942b992
6
+ metadata.gz: f5b91d698a7e54ff9353862f75fd443ebb92a85533d55c8eb9825b9ce7b00734c352f4731327f53506bc6095e217c6a714deea61e3443af148d54381771d1499
7
+ data.tar.gz: 35c982bad6e284756c23282cf02958ba6ce59254a5d11ced54bd95817dcb21ed85aced7f2aec6ccb70cdba921814cba2a531b19d0b42c369f490faf848ea84db
data/README.md CHANGED
@@ -17,9 +17,10 @@ any object, to obtain a ruby code on how it was created.
17
17
 
18
18
  1. [Installation](#installation)
19
19
  2. [Usage](#usage)
20
+ 1. [Minitest](#minitest)
20
21
  3. [Handling complex parameters and object constructors](#handling-complex-parameters-and-object-constructors)
21
22
  4. [Capturing Exceptions](#capturing-exceptions)
22
- 5. [Auto Stubbing](#Auto stubbing)
23
+ 5. [Auto Stubbing](#auto-stubbing)
23
24
  6. [Object Deconstruction Utility](#object-deconstruction-utility)
24
25
  1. [Using the Object deconstructor in rails](#using-the-object-deconstructor-in-rails)
25
26
  7. [Things to do after](#things-to-do-after)
@@ -208,7 +209,43 @@ RSpec.describe Digest::MD5 do
208
209
  end
209
210
  ```
210
211
 
211
- Only RSpec is supported at this point. But other testing frameworks should be trivial to add support to.
212
+ ## Minitest
213
+
214
+ The minitest test framework is also supported, simply use Pretentious.minitest_for instead
215
+
216
+ ```ruby
217
+ Pretentious.minitest_for(Meme) do
218
+ meme = Meme.new
219
+ meme.i_can_has_cheezburger?
220
+ meme.will_it_blend?
221
+ end
222
+ ```
223
+
224
+ outputs:
225
+
226
+ ```ruby
227
+ require 'test_helper'
228
+ require "minitest/autorun"
229
+
230
+ class TestMeme < Minitest::Test
231
+ end
232
+
233
+ class Scenario1 < TestMeme
234
+ def setup
235
+ @fixture = Meme.new
236
+ end
237
+
238
+ def test_current_expectation
239
+
240
+ # Meme#i_can_has_cheezburger? should return OHAI!
241
+ assert_equal "OHAI!", @fixture.i_can_has_cheezburger?
242
+
243
+ # Meme#will_it_blend? should return YES!
244
+ assert_equal "YES!", @fixture.will_it_blend?
245
+
246
+ end
247
+ end
248
+ ```
212
249
 
213
250
  ## Handling complex parameters and object constructors
214
251
 
@@ -323,7 +360,7 @@ should generate the following in rspec
323
360
 
324
361
  ## Auto stubbing
325
362
 
326
- Too lazy to generate rspec-mocks stubs? Let the Pretentious gem to it for you.
363
+ Too lazy to generate rspec-mocks stubs? Let the Pretentious gem do it for you.
327
364
 
328
365
  Simply call the _stub method on a class and pass the classes you want to generate
329
366
  stubs for when passing calling spec_for (see below):
data/bin/ddtgen CHANGED
@@ -7,16 +7,12 @@ require "readline"
7
7
  require 'json'
8
8
  require 'fileutils'
9
9
 
10
- $test_framework = :rspec
11
- $output_folder = 'spec'
12
-
13
10
  # ddtgen example.rb -t rspec -o rspec/
14
11
  options = OptionParser.new do |o|
15
12
  o.banner =
16
13
  "Usage: ddtgen FILENAME [options] # Generates tests using the specified example file\n"
17
14
  o.separator ""
18
15
  o.separator "options:"
19
- o.on('-t','--test-type','test framework to use (default :rspec)') { |b| $test_framework = b.to_sym}
20
16
  o.on('-o','--output-dir','folder to place the files in') { |b| $output_folder = b}
21
17
  o.parse!
22
18
  end
@@ -43,7 +39,7 @@ eval(example_body, binding, filename, 1)
43
39
 
44
40
  #collect results
45
41
 
46
- FileUtils.mkdir_p $output_folder
42
+
47
43
 
48
44
  module DdtUtils
49
45
  def self.to_underscore(str)
@@ -52,21 +48,13 @@ module DdtUtils
52
48
  end
53
49
 
54
50
  Pretentious.last_results.each { |klass, result|
55
-
56
- klass_name_parts = klass.name.split('::')
57
- last_part = klass_name_parts.pop
58
-
59
- filename = File.join($output_folder,"#{DdtUtils.to_underscore(last_part)}_spec.rb")
51
+ output_folder = result[:generator].location(output_folder)
52
+ FileUtils.mkdir_p output_folder
53
+ result[:generator].helper(output_folder)
54
+ filename = result[:generator].naming(output_folder, klass)
60
55
  File.open(filename, 'w') {
61
- |f| f.write(result)
56
+ |f| f.write(result[:output])
62
57
  }
63
58
  puts "#{filename}"
64
59
  }
65
60
 
66
- filename = File.join($output_folder,"spec_helper.rb")
67
- unless File.exists?(filename)
68
- File.open(filename, 'w') {
69
- |f| f.write("#Place your requires here")
70
- }
71
- puts "#{filename}"
72
- end
data/example.rb CHANGED
@@ -76,8 +76,8 @@ Pretentious.spec_for(TestClassForAutoStub._stub(ClassUsedByTestClass, AnotherCla
76
76
  instance.method_that_uses_the_class_to_stub
77
77
  end
78
78
 
79
- #Pretentious.spec_for(Pretentious::Deconstructor) do
80
- # deconstructor = Pretentious::Deconstructor.new
81
- # another_object = TestClass1.new("test")
82
- # deconstructor.build_tree(another_object)
83
- #end
79
+ Pretentious.minitest_for(Meme) do
80
+ meme = Meme.new
81
+ meme.i_can_has_cheezburger?
82
+ meme.will_it_blend?
83
+ end
data/lib/pretentious.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "pretentious/version"
2
2
  require "pretentious/rspec_generator"
3
+ require "pretentious/minitest_generator"
3
4
  require "pretentious/recorded_proc"
4
5
  require "pretentious/generator"
5
6
  require 'binding_of_caller'
@@ -21,17 +22,17 @@ end
21
22
  Thread.class_eval do
22
23
 
23
24
  def _push_context(context)
24
- @_context = @_context || []
25
+ @_context ||= []
25
26
  @_context << context
26
27
  end
27
28
 
28
29
  def _current_context
29
- @_context = @_context || []
30
+ @_context ||= []
30
31
  @_context.last
31
32
  end
32
33
 
33
34
  def _all_context
34
- @_context = @_context || []
35
+ @_context ||= []
35
36
  end
36
37
 
37
38
  def _pop_context
@@ -42,7 +43,14 @@ end
42
43
  module Pretentious
43
44
 
44
45
  def self.spec_for(*klasses, &block)
45
- @results = @results || {}
46
+ @results ||= {}
47
+ Pretentious::Generator.test_generator = Pretentious::RspecGenerator
48
+ @results.merge!(Pretentious::Generator.generate_for(*klasses, &block))
49
+ end
50
+
51
+ def self.minitest_for(*klasses, &block)
52
+ @results ||= {}
53
+ Pretentious::Generator.test_generator = Pretentious::MinitestGenerator
46
54
  @results.merge!(Pretentious::Generator.generate_for(*klasses, &block))
47
55
  end
48
56
 
@@ -381,7 +381,7 @@ module Pretentious
381
381
  all_results[klass] = []
382
382
  end
383
383
 
384
- all_results[klass] = generator.output
384
+ all_results[klass] = {output: generator.output, generator: generator.class }
385
385
 
386
386
  } unless klasses.nil?
387
387
 
@@ -0,0 +1,326 @@
1
+ class Pretentious::MinitestGenerator
2
+
3
+ def initialize(options = {})
4
+ @deconstructor = Pretentious::Deconstructor.new
5
+ indentation_count = options[:indentation] || 2
6
+ @output_buffer = ""
7
+ @_indentation = ""
8
+ indentation_count.times do
9
+ @_indentation << " "
10
+ end
11
+ end
12
+
13
+ def indentation(level)
14
+ buffer = ""
15
+ level.times do
16
+ buffer << @_indentation
17
+ end
18
+ buffer
19
+ end
20
+
21
+ def buffer(line, level = 0)
22
+ @output_buffer << "#{indentation(level)}#{line}\n"
23
+ end
24
+
25
+ def whitespace(level = 0)
26
+ @output_buffer << "#{indentation(level)}\n"
27
+ end
28
+
29
+ def begin_spec(test_class)
30
+ @test_class = test_class
31
+ buffer("require 'test_helper'")
32
+ buffer('require "minitest/autorun"')
33
+ whitespace
34
+ buffer("class Test#{test_class.name} < Minitest::Test")
35
+ buffer("end")
36
+ whitespace
37
+ end
38
+
39
+ def end_spec
40
+ end
41
+
42
+ def output
43
+ @output_buffer
44
+ end
45
+
46
+ def generate(test_instance, instance_count)
47
+ if (test_instance.is_a? Class)
48
+ #class methods
49
+ class_method_calls = test_instance.method_calls_by_method
50
+ generate_specs("#{test_instance.test_class.name}::",test_instance.test_class.name, class_method_calls, test_instance.let_variables)
51
+ else
52
+ buffer("class Scenario#{instance_count} < Test#{@test_class.name}",0)
53
+
54
+ buffer("def setup",1)
55
+ declarations = {}
56
+ dependencies = []
57
+
58
+ args = test_instance._init_arguments[:params]
59
+ block = test_instance._init_arguments[:block]
60
+ dependencies = dependencies | args
61
+
62
+ unless block.nil?
63
+ dependencies << block
64
+ end
65
+
66
+ block_source = if !block.nil? && block.is_a?(Pretentious::RecordedProc)
67
+ get_block_source(block, test_instance.init_let_variables, declarations, @_indentation * 2)
68
+ else
69
+ ''
70
+ end
71
+
72
+ if (dependencies.size > 0)
73
+ buffer(declare_dependencies(dependencies, test_instance.init_let_variables, 2 * @_indentation.length, declarations))
74
+ end
75
+
76
+ if (args.size > 0)
77
+ buffer("@fixture = #{test_instance.test_class.name}.new(#{params_generator(args, test_instance.init_let_variables, declarations)})#{block_source}",3)
78
+ else
79
+ buffer("@fixture = #{test_instance.test_class.name}.new#{block_source}",2)
80
+ end
81
+ buffer("end", 1)
82
+ whitespace
83
+
84
+ method_calls = test_instance.method_calls_by_method
85
+
86
+ generate_specs("#{test_instance.test_class.name}#","@fixture",method_calls, test_instance.let_variables)
87
+
88
+ buffer('end',0)
89
+ whitespace
90
+ end
91
+
92
+ end
93
+
94
+ private
95
+
96
+
97
+
98
+ def proc_function_generator(block, method)
99
+ "func_#{method.to_s}(#{Pretentious::Deconstructor.block_params_generator(block)})"
100
+ end
101
+
102
+ def get_block_source(block,let_variables, declared,indentation)
103
+ #output = ''
104
+ #output << "{ #{Pretentious::Deconstructor.block_params_generator(block)}\n"
105
+ #output << Pretentious::Deconstructor.proc_body(block, let_variables, declared,indentation)
106
+ #output << "#{indentation}}"
107
+ #output
108
+ " &#{Pretentious::Deconstructor.pick_name(let_variables, block.target_proc.object_id, declared)}"
109
+ end
110
+
111
+ def generate_expectation(fixture, method, let_variables, declarations, params, block, result)
112
+ block_source = if !block.nil? && block.is_a?(Pretentious::RecordedProc)
113
+ get_block_source(block, let_variables, declarations, @_indentation * 2)
114
+ else
115
+ ''
116
+ end
117
+
118
+ statement = if params.size > 0
119
+ "#{fixture}.#{method.to_s}(#{params_generator(params, let_variables, declarations)})#{block_source}"
120
+ else
121
+ stmt = []
122
+ stmt << "#{fixture}.#{method.to_s}"
123
+ stmt << "#{block_source}" unless block_source.empty?
124
+ stmt.join(' ')
125
+ end
126
+
127
+ if (result.kind_of? Exception)
128
+ buffer(pick_matcher(statement, result), 2)
129
+ else
130
+ buffer(pick_matcher(statement, result), 2)
131
+ end
132
+ end
133
+
134
+ def generate_specs(context_prefix, fixture, method_calls, let_variables)
135
+ buffer("def test_current_expectation",1)
136
+ whitespace
137
+ declaration = {}
138
+ #collect all params
139
+ params_collection = []
140
+ mocks_collection = {}
141
+
142
+ method_calls.each_key do |k|
143
+ info_blocks_arr = method_calls[k]
144
+ info_blocks_arr.each do |block|
145
+ params_collection = params_collection | block[:params]
146
+ if (!Pretentious::Deconstructor.is_primitive?(block[:result]) && !block[:result].kind_of?(Exception))
147
+ params_collection << block[:result]
148
+ end
149
+
150
+ unless (block[:block].nil?)
151
+ params_collection << block[:block]
152
+ end
153
+
154
+ block[:context][:calls].each do |mock_block|
155
+ k = "#{mock_block[:class]}_#{mock_block[:method]}"
156
+
157
+ if mocks_collection[k].nil?
158
+ mocks_collection[k] = []
159
+ end
160
+
161
+ mocks_collection[k] << mock_block
162
+ params_collection << mock_block[:result]
163
+
164
+ end if block[:context]
165
+
166
+
167
+ end
168
+
169
+ end
170
+
171
+ if (params_collection.size > 0)
172
+ buffer(declare_dependencies(params_collection, let_variables, 3 * @_indentation.length, declaration))
173
+ end
174
+
175
+ if (mocks_collection.keys.size > 0)
176
+ buffer(generate_rspec_stub(mocks_collection, let_variables, 3 * @_indentation.length, declaration))
177
+ end
178
+
179
+ method_calls.each_key do |k|
180
+ info_blocks_arr = method_calls[k]
181
+
182
+ info_blocks_arr.each do |block|
183
+
184
+ params_desc_str = if block[:params].size > 0
185
+ "when passed #{desc_params(block)}"
186
+ else
187
+ ""
188
+ end
189
+
190
+ buffer("# #{context_prefix}#{k} #{params_desc_str} should return #{block[:result]}", 3)
191
+ generate_expectation(fixture, k, let_variables, declaration, block[:params], block[:block], block[:result])
192
+
193
+ whitespace
194
+ end
195
+
196
+
197
+ end
198
+ buffer("end", 1)
199
+ end
200
+
201
+ def generate_rspec_stub(mocks_collection, let_variables, indentation_level , declaration)
202
+ indentation = ""
203
+
204
+ indentation_level.times {
205
+ indentation << ' '
206
+ }
207
+ str = ""
208
+ mocks_collection.each do |k,values|
209
+ vals = values.collect { |v| Pretentious::value_ize(v[:result], let_variables, declaration) }
210
+
211
+ #check if all vals are the same and just use one
212
+ vals = [vals[0]] if vals.uniq.size == 1
213
+
214
+ str << "#{indentation}allow_any_instance_of(#{values[0][:class].to_s}).to receive(:#{values[0][:method].to_s}).and_return(#{vals.join(', ')})\n"
215
+ end
216
+ str
217
+ end
218
+
219
+ #def generate_specs(context_prefix, fixture, method_calls, let_variables)
220
+ # method_calls.each_key do |k|
221
+ # info_blocks_arr = method_calls[k]
222
+ #
223
+ # buffer("context \"#{context_prefix}#{k}\" do", 1)
224
+ #
225
+ # whitespace
226
+ # info_blocks_arr.each do |block|
227
+ # buffer("it '#{desc_params(block)} returns #{block[:result]}' do",2)
228
+ # whitespace
229
+ # if block[:params].size > 0
230
+ # buffer(declare_dependencies(block[:params], let_variables, 3))
231
+ # buffer("expect(#{fixture}.#{k.to_s}(#{params_generator(block[:params], let_variables)})).to #{pick_matcher(block[:result])}",3)
232
+ # else
233
+ # buffer("expect(#{fixture}.#{k.to_s}).to #{pick_matcher(block[:result])}",3)
234
+ # end
235
+ # whitespace
236
+ # buffer("end",2)
237
+ # whitespace
238
+ # end
239
+ #
240
+ # buffer("end", 1)
241
+ # whitespace
242
+ # end
243
+ #end
244
+
245
+ def pick_matcher(statement, result)
246
+ if result.is_a? TrueClass
247
+ "assert #{statement}"
248
+ elsif result.is_a? FalseClass
249
+ "refute #{statement}"
250
+ elsif result.nil?
251
+ "assert_nil #{Pretentious::value_ize(result, nil, nil)}"
252
+ elsif result.kind_of? Exception
253
+ "assert_raises(#{result.class.to_s}) { #{statement} }"
254
+ else
255
+ "assert_equal #{Pretentious::value_ize(result, nil, nil)}, #{statement}"
256
+ end
257
+ end
258
+
259
+
260
+
261
+ def desc_params(block)
262
+ params = []
263
+ args = block[:params]
264
+ names = block[:names]
265
+ n = 0
266
+ #puts args.inspect
267
+ return "" if args.nil?
268
+
269
+ args.each do |arg|
270
+ param_name = names[n][1].to_s
271
+ arg_value = (arg.is_a? String) ? "#{arg.dump}" : "#{arg.to_s}"
272
+ if (param_name.empty?)
273
+ params << "#{arg_value}"
274
+ else
275
+ params << "#{param_name} = #{arg_value}"
276
+ end
277
+
278
+ n+=1
279
+ end
280
+ params.join(" ,")
281
+ end
282
+
283
+ def declare_dependencies(args, variable_map, level, declarations)
284
+ deconstructor = Pretentious::Deconstructor.new
285
+
286
+ args = remove_primitives(args, variable_map)
287
+ deconstructor.deconstruct_to_ruby(level, variable_map, declarations, *args)
288
+ end
289
+
290
+ def remove_primitives(args, let_lookup)
291
+ args.select { |a| let_lookup.include?(a.object_id) || !Pretentious::Deconstructor.is_primitive?(a) }
292
+ end
293
+
294
+ def params_generator(args, let_variables, declared_names)
295
+ params = []
296
+ args.each do |arg|
297
+ if (!let_variables.nil? && let_variables[arg.object_id])
298
+ params << Pretentious::Deconstructor.pick_name(let_variables, arg.object_id, declared_names)
299
+ else
300
+ params << Pretentious::value_ize(arg, let_variables, declared_names)
301
+ end
302
+
303
+ end
304
+ params.join(", ")
305
+ end
306
+
307
+ def self.location(output_folder)
308
+ output_folder.nil? ? "test" : File.join(output_folder, "test")
309
+ end
310
+
311
+ def self.naming(output_folder, klass)
312
+ klass_name_parts = klass.name.split('::')
313
+ last_part = klass_name_parts.pop
314
+ File.join(output_folder, "test_#{DdtUtils.to_underscore(last_part)}.rb")
315
+ end
316
+
317
+ def self.helper(output_folder)
318
+ filename = File.join(output_folder,"test_helper.rb")
319
+ unless File.exists?(filename)
320
+ File.open(filename, 'w') {
321
+ |f| f.write("#Place your requires here")
322
+ }
323
+ puts "#{filename}"
324
+ end
325
+ end
326
+ end
@@ -305,4 +305,23 @@ class Pretentious::RspecGenerator
305
305
  params.join(", ")
306
306
  end
307
307
 
308
+ def self.location(output_folder)
309
+ output_folder.nil? ? "spec" : File.join(output_folder, "spec" )
310
+ end
311
+
312
+ def self.naming(output_folder, klass)
313
+ klass_name_parts = klass.name.split('::')
314
+ last_part = klass_name_parts.pop
315
+ File.join(output_folder, "#{DdtUtils.to_underscore(last_part)}_spec.rb")
316
+ end
317
+
318
+ def self.helper(output_folder)
319
+ filename = File.join(output_folder,"spec_helper.rb")
320
+ unless File.exists?(filename)
321
+ File.open(filename, 'w') {
322
+ |f| f.write("#Place your requires here")
323
+ }
324
+ puts "#{filename}"
325
+ end
326
+ end
308
327
  end
@@ -1,3 +1,3 @@
1
1
  module Pretentious
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/pretentious.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "minitest"
24
25
  end
@@ -113,7 +113,7 @@ RSpec.describe Pretentious::Generator do
113
113
  instance.message("hello")
114
114
  end
115
115
 
116
- expect(call_artifacts).to eq({TestClass=>
116
+ expect(call_artifacts).to eq({TestClass=>{output:
117
117
  [{:begin=>TestClass},
118
118
  {:instance=>"TestClassImpostor",
119
119
  :instance_method_calls=>
@@ -122,7 +122,7 @@ RSpec.describe Pretentious::Generator do
122
122
  :block=>nil,
123
123
  :names=>[[:req, :params1]],
124
124
  :context=>{:calls=>[]}, :result=>"hello"}],
125
- :instance_count=>1}, :end]})
125
+ :instance_count=>1}, :end], generator: DummyGenerator}})
126
126
  end
127
127
 
128
128
  context "auto mocks generator" do
@@ -134,14 +134,14 @@ RSpec.describe Pretentious::Generator do
134
134
  instance.method_with_usage
135
135
  end
136
136
 
137
- expect(call_artifacts).to eq({ TestClass => [{:begin=>TestClass},
137
+ expect(call_artifacts).to eq({ TestClass => {output: [{:begin=>TestClass},
138
138
  {:instance=>"TestClassImpostor",
139
139
  :instance_method_calls=>[{:method=>:method_with_usage,
140
140
  :params=>[], :block=>nil, :names=>[],
141
141
  :context=>{:calls=>[{:method=>:test_method, :params=>[],
142
142
  :block=>nil, :names=>[], :result=>"a return string",
143
143
  :class=>TestSubClass}]}, :result=>"a return string"}],
144
- :instance_count=>1}, :end]})
144
+ :instance_count=>1}, :end], generator: DummyGenerator}})
145
145
  end
146
146
  end
147
147
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Pretentious::Generator do
4
+
5
+ context 'Pretentious::Deconstructor#build_tree' do
6
+
7
+ before do
8
+ @fixture = Pretentious::Generator.new
9
+ Pretentious::Generator.test_generator = Pretentious::MinitestGenerator
10
+ end
11
+
12
+ it "classes should have a stub class section" do
13
+ Fibonacci._stub(String)
14
+ expect(Fibonacci._get_mock_classes).to eq([String])
15
+ end
16
+
17
+ it "tracks object calls" do
18
+ result = Pretentious::Generator.generate_for(Fibonacci) do
19
+ Fibonacci.say_hello
20
+ end
21
+ expect(result).to eq({Fibonacci =>{output: "require 'test_helper'\nrequire \"minitest/autorun\"\n\nclass TestFibonacci < Minitest::Test\nend\n\n def test_current_expectation\n\n # Fibonacci::say_hello should return hello\n assert_equal \"hello\", Fibonacci.say_hello\n\n end\n",
22
+ generator: Pretentious::MinitestGenerator }})
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -6,6 +6,7 @@ RSpec.describe Pretentious::Generator do
6
6
 
7
7
  before do
8
8
  @fixture = Pretentious::Generator.new
9
+ Pretentious::Generator.test_generator = Pretentious::RspecGenerator
9
10
  end
10
11
 
11
12
  it "classes should have a stub class section" do
@@ -18,8 +19,8 @@ RSpec.describe Pretentious::Generator do
18
19
  Fibonacci.say_hello
19
20
  end
20
21
  expect(result).to eq({
21
- Fibonacci => "require 'spec_helper'\n\nRSpec.describe Fibonacci do\n\n it 'should pass current expectations' do\n\n # Fibonacci::say_hello should return hello\n expect( Fibonacci.say_hello ).to eq(\"hello\")\n\n end\nend\n"
22
- })
22
+ Fibonacci =>{output: "require 'spec_helper'\n\nRSpec.describe Fibonacci do\n\n it 'should pass current expectations' do\n\n # Fibonacci::say_hello should return hello\n expect( Fibonacci.say_hello ).to eq(\"hello\")\n\n end\nend\n",
23
+ generator: Pretentious::RspecGenerator}})
23
24
  end
24
25
 
25
26
  end
@@ -21,25 +21,25 @@ RSpec.describe TestClass1 do
21
21
  context 'Scenario 2' do
22
22
  before do
23
23
 
24
- var_2158495560 = "test"
25
- another_object = TestClass1.new(var_2158495560)
26
- var_2158482220 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
24
+ var_2157436060 = "test"
25
+ another_object = TestClass1.new(var_2157436060)
26
+ var_2157430640 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
27
27
 
28
- @fixture = TestClass1.new(var_2158482220)
28
+ @fixture = TestClass1.new(var_2157430640)
29
29
 
30
30
  end
31
31
 
32
32
  it 'should pass current expectations' do
33
33
 
34
- var_2158495560 = "test"
35
- another_object = TestClass1.new(var_2158495560)
36
- var_2158482220 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
37
- var_2158348900 = Proc.new { |message|
38
- var_2158482220
34
+ var_2157436060 = "test"
35
+ another_object = TestClass1.new(var_2157436060)
36
+ var_2157430640 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
37
+ var_2157617620 = Proc.new { |message|
38
+ var_2157430640
39
39
  }
40
40
 
41
41
  e = nil
42
- var_2158332200 = Proc.new {
42
+ var_2173948680 = Proc.new {
43
43
  # Variable return values ... can't figure out what goes in here...
44
44
  }
45
45
 
@@ -50,11 +50,11 @@ RSpec.describe TestClass1 do
50
50
  # TestClass1#print_message should return
51
51
  expect( @fixture.print_message ).to be_nil
52
52
 
53
- # TestClass1#set_block should return #<Pretentious::RecordedProc:0x000001014b2380@example.rb:71>
54
- expect( @fixture.set_block &var_2158348900 ).to eq(var_2158348900)
53
+ # TestClass1#set_block should return #<Pretentious::RecordedProc:0x0000010327a868@example.rb:71>
54
+ expect( @fixture.set_block &var_2157617620 ).to eq(var_2157617620)
55
55
 
56
- # TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x00000101500d00 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2158495560=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000101500d00 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2158495560=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000101500d00 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2158495560=>"message"}>}}
57
- expect( @fixture.call_block &var_2158332200 ).to eq(var_2158482220)
56
+ # TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x000001012fb7a8 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2157436060=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x000001012fb7a8 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2157436060=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x000001012fb7a8 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2157436060=>"message"}>}}
57
+ expect( @fixture.call_block &var_2173948680 ).to eq(var_2157430640)
58
58
 
59
59
  # TestClass1#something_is_wrong should return StandardError
60
60
  expect { @fixture.something_is_wrong }.to raise_error
@@ -5,8 +5,8 @@ RSpec.describe TestClass3 do
5
5
  context 'Scenario 1' do
6
6
  before do
7
7
 
8
- var_2158495560 = "test"
9
- another_object = TestClass1.new(var_2158495560)
8
+ var_2157436060 = "test"
9
+ another_object = TestClass1.new(var_2157436060)
10
10
  args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
11
11
  test_class_one = TestClass1.new(args)
12
12
  args_1 = "This is message 2"
@@ -27,8 +27,8 @@ RSpec.describe TestClass3 do
27
27
  context 'Scenario 2' do
28
28
  before do
29
29
 
30
- var_2158495560 = "test"
31
- another_object = TestClass1.new(var_2158495560)
30
+ var_2157436060 = "test"
31
+ another_object = TestClass1.new(var_2157436060)
32
32
  args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
33
33
  test_class_one = TestClass1.new(args)
34
34
  args_1 = "This is message 2"
@@ -5,13 +5,13 @@ RSpec.describe TestClass4 do
5
5
  context 'Scenario 1' do
6
6
  before do
7
7
 
8
- var_2158495560 = "test"
9
- var_2158363380 = Proc.new {
8
+ var_2157436060 = "test"
9
+ var_2157471500 = Proc.new {
10
10
  "test"
11
11
  }
12
12
 
13
13
 
14
- @fixture = TestClass4.new &var_2158363380
14
+ @fixture = TestClass4.new &var_2157471500
15
15
 
16
16
  end
17
17
 
@@ -11,7 +11,7 @@ RSpec.describe TestClassForAutoStub do
11
11
 
12
12
  it 'should pass current expectations' do
13
13
 
14
- var_2157894280 = ["Hello Glorious world", "HI THERE!!!!"]
14
+ var_2173604520 = ["Hello Glorious world", "HI THERE!!!!"]
15
15
 
16
16
  allow_any_instance_of(ClassUsedByTestClass).to receive(:stubbed_method).and_return("Hello Glorious world")
17
17
  allow_any_instance_of(AnotherClassUsedByTestClass).to receive(:get_message).and_return("HI THERE!!!!")
@@ -11,7 +11,7 @@ RSpec.describe TestClassForMocks do
11
11
 
12
12
  it 'should pass current expectations' do
13
13
 
14
- var_2158090860 = [2, 3, 4, 5]
14
+ var_2173778440 = [2, 3, 4, 5]
15
15
 
16
16
  allow_any_instance_of(TestMockSubClass).to receive(:test_method).and_return("a return string")
17
17
  allow_any_instance_of(TestMockSubClass).to receive(:increment_val).and_return(2, 3, 4, 5)
@@ -40,12 +40,12 @@ RSpec.describe TestClassForMocks do
40
40
 
41
41
  it 'should pass current expectations' do
42
42
 
43
- var_2158024660 = {val: 1, str: "hello world", message: "a message"}
43
+ var_2173712460 = {val: 1, str: "hello world", message: "a message"}
44
44
 
45
- allow_any_instance_of(TestMockSubClass).to receive(:return_hash).and_return(var_2158024660)
45
+ allow_any_instance_of(TestMockSubClass).to receive(:return_hash).and_return(var_2173712460)
46
46
 
47
47
  # TestClassForMocks#method_with_usage3 when passed message = "a message" should return {:val=>1, :str=>"hello world", :message=>"a message"}
48
- expect( @fixture.method_with_usage3("a message") ).to eq(var_2158024660)
48
+ expect( @fixture.method_with_usage3("a message") ).to eq(var_2173712460)
49
49
 
50
50
  end
51
51
  end
@@ -0,0 +1 @@
1
+ require_relative '../test_classes'
data/test/test_meme.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require "minitest/autorun"
3
+
4
+ class TestMeme < Minitest::Test
5
+ end
6
+
7
+ class Scenario1 < TestMeme
8
+ def setup
9
+ @fixture = Meme.new
10
+ end
11
+
12
+ def test_current_expectation
13
+
14
+ # Meme#i_can_has_cheezburger? should return OHAI!
15
+ assert_equal "OHAI!", @fixture.i_can_has_cheezburger?
16
+
17
+ # Meme#will_it_blend? should return YES!
18
+ assert_equal "YES!", @fixture.will_it_blend?
19
+
20
+ end
21
+ end
22
+
data/test_classes.rb CHANGED
@@ -15,6 +15,15 @@ class Fibonacci
15
15
 
16
16
  end
17
17
 
18
+ class Meme
19
+ def i_can_has_cheezburger?
20
+ "OHAI!"
21
+ end
22
+
23
+ def will_it_blend?
24
+ "YES!"
25
+ end
26
+ end
18
27
 
19
28
  class TestClass1
20
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretentious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Do you have a pretentious boss or dev lead that pushes you to embrace
70
84
  tdd but for reasons hate it or them? here is a gem to deal with that.
71
85
  email:
@@ -85,6 +99,7 @@ files:
85
99
  - lib/pretentious.rb
86
100
  - lib/pretentious/deconstructor.rb
87
101
  - lib/pretentious/generator.rb
102
+ - lib/pretentious/minitest_generator.rb
88
103
  - lib/pretentious/recorded_proc.rb
89
104
  - lib/pretentious/rspec_generator.rb
90
105
  - lib/pretentious/version.rb
@@ -94,6 +109,7 @@ files:
94
109
  - spec/fibonacci_spec.rb
95
110
  - spec/generator_spec.rb
96
111
  - spec/m_d5_spec.rb
112
+ - spec/minitest_generator_spec.rb
97
113
  - spec/prententious_spec.rb
98
114
  - spec/spec_helper.rb
99
115
  - spec/test_class1_spec.rb
@@ -103,6 +119,8 @@ files:
103
119
  - spec/test_class_for_auto_stub_spec.rb
104
120
  - spec/test_class_for_mocks_spec.rb
105
121
  - test/test_generator.rb
122
+ - test/test_helper.rb
123
+ - test/test_meme.rb
106
124
  - test_classes.rb
107
125
  homepage: https://github.com/jedld/pretentious
108
126
  licenses:
@@ -134,6 +152,7 @@ test_files:
134
152
  - spec/fibonacci_spec.rb
135
153
  - spec/generator_spec.rb
136
154
  - spec/m_d5_spec.rb
155
+ - spec/minitest_generator_spec.rb
137
156
  - spec/prententious_spec.rb
138
157
  - spec/spec_helper.rb
139
158
  - spec/test_class1_spec.rb
@@ -143,4 +162,6 @@ test_files:
143
162
  - spec/test_class_for_auto_stub_spec.rb
144
163
  - spec/test_class_for_mocks_spec.rb
145
164
  - test/test_generator.rb
165
+ - test/test_helper.rb
166
+ - test/test_meme.rb
146
167
  has_rdoc: