pretentious 0.1.10 → 0.1.11
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 +11 -1
- data/lib/pretentious/context.rb +16 -10
- data/lib/pretentious/generator.rb +3 -6
- data/lib/pretentious/generator_base.rb +16 -0
- data/lib/pretentious/minitest_generator.rb +16 -15
- data/lib/pretentious/rspec_generator.rb +26 -25
- data/lib/pretentious/version.rb +1 -1
- data/run_test.sh +1 -1
- data/spec/generated/fibonacci_spec.rb +10 -11
- data/spec/generated/m_d5_spec.rb +6 -7
- data/spec/generated/test_class1_spec.rb +2 -3
- data/spec/generated/test_class2_spec.rb +2 -3
- data/spec/generated/test_class3_spec.rb +1 -2
- data/spec/generated/test_class4_spec.rb +1 -2
- data/spec/generated/test_class_for_auto_stub_spec.rb +2 -3
- data/spec/generated/test_class_for_mocks_spec.rb +3 -4
- data/spec/generator_spec.rb +12 -1
- data/spec/minitest_generator_spec.rb +1 -3
- data/spec/prententious_spec.rb +3 -3
- data/test/generated/test_fibonacci.rb +2 -3
- data/test/generated/test_m_d5.rb +2 -3
- data/test/generated/test_meme.rb +2 -3
- data/test/generated/test_test_class1.rb +3 -4
- data/test/generated/test_test_class2.rb +2 -3
- data/test/generated/test_test_class3.rb +2 -3
- data/test/generated/test_test_class4.rb +2 -3
- data/test/generated/test_test_class_for_mocks.rb +3 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad7ffc54896b981b06cc3c99e0bf0830bbedcd55
|
4
|
+
data.tar.gz: b97864d3c92ece3721f5dc26769ce493010f12d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87e16f197e827a41cb33f1c0c7490470a765fcc547c0295a66acce3fa013e98774f531f99d41791df87fd48d449d99449e4e19e192c29980e8152cfee7bd24e
|
7
|
+
data.tar.gz: 1de33c5ded9cb5c9d9456ad6e5cf01bc0a5a0a8c44c9bf3eea8d4c60ccd9ef05f481620b0e406f4e730010855987164d4b9c0221647cbe7d7a277bcb42f0ad91
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
+
## 0.1.11 (2015-12-12)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- fix code style
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
- matchers should now prefer variable references in assertions if previously declared
|
10
|
+
|
1
11
|
## 0.1.10 (2015-12-11)
|
2
12
|
|
3
13
|
Bugfixes:
|
4
14
|
|
5
15
|
- fix regression wherein method_missing is not handled properly
|
6
16
|
|
7
|
-
|
17
|
+
Features:
|
8
18
|
|
9
19
|
- Fix weird generated comments
|
10
20
|
|
data/lib/pretentious/context.rb
CHANGED
@@ -47,16 +47,8 @@ module Pretentious
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def pick_name(object_id, value = :no_value_passed)
|
50
|
-
|
51
|
-
|
52
|
-
if @declared_names
|
53
|
-
@declared_names.each do |k, v|
|
54
|
-
object_id_to_declared_names[v[:object_id]] = k if v
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# return immediately if already mapped
|
59
|
-
return object_id_to_declared_names[object_id] if object_id_to_declared_names.include? object_id
|
50
|
+
var_name = map_name(object_id)
|
51
|
+
return var_name if var_name
|
60
52
|
|
61
53
|
var_name = "var_#{object_id}"
|
62
54
|
|
@@ -99,6 +91,20 @@ module Pretentious
|
|
99
91
|
Pretentious.value_ize(self, value)
|
100
92
|
end
|
101
93
|
|
94
|
+
def map_name(object_id)
|
95
|
+
object_id_to_declared_names = {}
|
96
|
+
|
97
|
+
if @declared_names
|
98
|
+
@declared_names.each do |k, v|
|
99
|
+
object_id_to_declared_names[v[:object_id]] = k if v
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# return immediately if already mapped
|
104
|
+
return object_id_to_declared_names[object_id] if object_id_to_declared_names.include? object_id
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
102
108
|
private
|
103
109
|
|
104
110
|
def provide_name
|
@@ -369,19 +369,16 @@ module Pretentious
|
|
369
369
|
|
370
370
|
generator = test_generator.new
|
371
371
|
generator.begin_spec(klass)
|
372
|
-
num = 1
|
373
372
|
|
374
|
-
new_standin_klass._instances
|
375
|
-
generator.generate(instance, num)
|
376
|
-
num += 1
|
377
|
-
end unless new_standin_klass._instances.nil?
|
373
|
+
generator.body(new_standin_klass._instances) unless new_standin_klass._instances.nil?
|
378
374
|
|
379
375
|
generator.end_spec
|
380
376
|
|
381
377
|
result = all_results[klass]
|
382
378
|
all_results[klass] = [] if result.nil?
|
383
379
|
|
384
|
-
|
380
|
+
result_output = generator.output.is_a?(String) ? generator.output.chomp : generator.output
|
381
|
+
all_results[klass] = { output: result_output, generator: generator.class }
|
385
382
|
end unless klasses.nil?
|
386
383
|
|
387
384
|
all_results
|
@@ -35,6 +35,14 @@ module Pretentious
|
|
35
35
|
[context, declarations]
|
36
36
|
end
|
37
37
|
|
38
|
+
def body(instances)
|
39
|
+
specs = []
|
40
|
+
instances.each_with_index do |instance, num|
|
41
|
+
specs << generate(instance, num + 1)
|
42
|
+
end
|
43
|
+
buffer_inline(specs.join("\n"))
|
44
|
+
end
|
45
|
+
|
38
46
|
protected
|
39
47
|
|
40
48
|
def declare_dependencies(context, args, level)
|
@@ -90,5 +98,13 @@ module Pretentious
|
|
90
98
|
def whitespace(level = 0)
|
91
99
|
@output_buffer << "#{indentation(level)}\n"
|
92
100
|
end
|
101
|
+
|
102
|
+
def prettify_method_name(method_name)
|
103
|
+
if method_name.to_s.end_with? '='
|
104
|
+
"#{method_name.to_s.chop} = "
|
105
|
+
else
|
106
|
+
method_name.to_s
|
107
|
+
end
|
108
|
+
end
|
93
109
|
end
|
94
110
|
end
|
@@ -5,7 +5,7 @@ module Pretentious
|
|
5
5
|
@test_class = test_class
|
6
6
|
buffer('# This file was automatically generated by the pretentious gem')
|
7
7
|
buffer("require 'minitest_helper'")
|
8
|
-
buffer(
|
8
|
+
buffer("require 'minitest/autorun'")
|
9
9
|
whitespace
|
10
10
|
buffer("class #{test_class.name}Test < Minitest::Test")
|
11
11
|
buffer('end')
|
@@ -19,21 +19,24 @@ module Pretentious
|
|
19
19
|
@output_buffer
|
20
20
|
end
|
21
21
|
|
22
|
+
private
|
23
|
+
|
22
24
|
def generate(test_instance, instance_count)
|
25
|
+
output_buffer = ''
|
23
26
|
if test_instance.is_a? Class
|
24
|
-
|
27
|
+
buffer_to_string(output_buffer, "class #{test_instance.test_class.name}Scenario#{instance_count} < #{@test_class.name}Test", 0)
|
25
28
|
|
26
29
|
# class methods
|
27
30
|
class_method_calls = test_instance.method_calls_by_method
|
28
31
|
context = Pretentious::Context.new(test_instance.let_variables)
|
29
|
-
|
32
|
+
buffer_inline_to_string(output_buffer, generate_specs(context, "#{test_instance.test_class.name}::",
|
30
33
|
test_instance.test_class.name, class_method_calls))
|
31
34
|
|
32
|
-
|
35
|
+
buffer_to_string(output_buffer, 'end', 0)
|
33
36
|
else
|
34
|
-
|
37
|
+
buffer_to_string(output_buffer, "class #{test_instance.test_class.name}Scenario#{instance_count} < #{@test_class.name}Test", 0)
|
35
38
|
|
36
|
-
|
39
|
+
buffer_to_string(output_buffer, 'def setup', 1)
|
37
40
|
|
38
41
|
context, declarations = setup_fixture(test_instance)
|
39
42
|
|
@@ -41,19 +44,17 @@ module Pretentious
|
|
41
44
|
specs_buffer = generate_specs(context.subcontext(declarations[:declaration]), "#{test_instance.test_class.name}#",
|
42
45
|
'@fixture', method_calls)
|
43
46
|
context.declared_names = {}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
buffer_inline_to_string(output_buffer, @deconstructor.build_output(context, 2 * @_indentation.length, declarations))
|
48
|
+
buffer_to_string(output_buffer, 'end', 1)
|
49
|
+
buffer_to_string(output_buffer, '')
|
47
50
|
|
48
|
-
|
51
|
+
buffer_inline_to_string(output_buffer, specs_buffer)
|
49
52
|
|
50
|
-
|
51
|
-
whitespace
|
53
|
+
buffer_to_string(output_buffer, 'end', 0)
|
52
54
|
end
|
55
|
+
output_buffer
|
53
56
|
end
|
54
57
|
|
55
|
-
private
|
56
|
-
|
57
58
|
def proc_function_generator(block, method)
|
58
59
|
"func_#{method}(#{Pretentious::Deconstructor.block_params_generator(block)})"
|
59
60
|
end
|
@@ -71,7 +72,7 @@ module Pretentious
|
|
71
72
|
end
|
72
73
|
|
73
74
|
statement = if params.size > 0
|
74
|
-
"#{fixture}.#{method}(#{params_generator(context, params)})#{block_source}"
|
75
|
+
"#{fixture}.#{prettify_method_name method}(#{params_generator(context, params)})#{block_source}"
|
75
76
|
else
|
76
77
|
stmt = []
|
77
78
|
m_stmt = "#{fixture}.#{method}"
|
@@ -16,36 +16,37 @@ module Pretentious
|
|
16
16
|
@output_buffer
|
17
17
|
end
|
18
18
|
|
19
|
+
private
|
20
|
+
|
19
21
|
def generate(test_instance, instance_count)
|
22
|
+
output_buffer = ''
|
20
23
|
if test_instance.is_a? Class
|
21
24
|
context = Pretentious::Context.new(test_instance.let_variables)
|
22
25
|
# class methods
|
23
26
|
class_method_calls = test_instance.method_calls_by_method
|
24
|
-
|
27
|
+
buffer_inline_to_string(output_buffer, generate_specs(0, context, "#{test_instance.test_class.name}::", test_instance.test_class.name,
|
25
28
|
class_method_calls))
|
26
29
|
else
|
27
|
-
|
30
|
+
buffer_to_string(output_buffer, "context 'Scenario #{instance_count}' do", 1)
|
28
31
|
|
29
|
-
|
32
|
+
buffer_to_string(output_buffer, 'before do', 2)
|
30
33
|
|
31
34
|
context, declarations = setup_fixture(test_instance)
|
32
35
|
method_calls = test_instance.method_calls_by_method
|
33
36
|
spec_context = context.subcontext(declarations[:declaration])
|
34
|
-
specs_buffer = generate_specs(spec_context, "#{test_instance.test_class.name}#", "@fixture", method_calls)
|
37
|
+
specs_buffer = generate_specs(1, spec_context, "#{test_instance.test_class.name}#", "@fixture", method_calls)
|
35
38
|
context.declared_names = {}
|
36
39
|
deconstruct_output = @deconstructor.build_output(context, 3 * @_indentation.length, declarations)
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
whitespace
|
41
|
+
buffer_inline_to_string(output_buffer, deconstruct_output)
|
42
|
+
buffer_to_string(output_buffer, 'end', 2)
|
43
|
+
buffer_to_string(output_buffer, '')
|
44
|
+
buffer_inline_to_string(output_buffer, specs_buffer)
|
45
|
+
buffer_to_string(output_buffer, 'end', 1)
|
44
46
|
end
|
47
|
+
output_buffer
|
45
48
|
end
|
46
49
|
|
47
|
-
private
|
48
|
-
|
49
50
|
def proc_function_generator(block, method)
|
50
51
|
"func_#{method}(#{Pretentious::Deconstructor.block_params_generator(block)})"
|
51
52
|
end
|
@@ -54,7 +55,7 @@ module Pretentious
|
|
54
55
|
" &#{context.pick_name(block.target_proc.object_id)}"
|
55
56
|
end
|
56
57
|
|
57
|
-
def generate_expectation(context, fixture, method, params, block, result)
|
58
|
+
def generate_expectation(indentation_level, context, fixture, method, params, block, result)
|
58
59
|
output = ''
|
59
60
|
block_source = if !block.nil? && block.is_a?(Pretentious::RecordedProc)
|
60
61
|
get_block_source(context, block)
|
@@ -63,7 +64,7 @@ module Pretentious
|
|
63
64
|
end
|
64
65
|
|
65
66
|
statement = if params.size > 0
|
66
|
-
"#{fixture}.#{method}(#{params_generator(context, params)})#{block_source}"
|
67
|
+
"#{fixture}.#{prettify_method_name(method)}(#{params_generator(context, params)})#{block_source}"
|
67
68
|
else
|
68
69
|
stmt = []
|
69
70
|
stmt << "#{fixture}.#{method}"
|
@@ -72,16 +73,16 @@ module Pretentious
|
|
72
73
|
end
|
73
74
|
|
74
75
|
if result.is_a? Exception
|
75
|
-
buffer_to_string(output, "expect { #{statement} }.to #{pick_matcher(context, result)}",
|
76
|
+
buffer_to_string(output, "expect { #{statement} }.to #{pick_matcher(context, result)}", indentation_level + 2)
|
76
77
|
else
|
77
|
-
buffer_to_string(output, "expect(#{statement}).to #{pick_matcher(context, result)}",
|
78
|
+
buffer_to_string(output, "expect(#{statement}).to #{pick_matcher(context, result)}", indentation_level + 2)
|
78
79
|
end
|
79
80
|
output
|
80
81
|
end
|
81
82
|
|
82
|
-
def generate_specs(context, context_prefix, fixture, method_calls)
|
83
|
+
def generate_specs(indentation_level, context, context_prefix, fixture, method_calls)
|
83
84
|
output = ''
|
84
|
-
buffer_to_string(output, "it 'should pass current expectations' do",
|
85
|
+
buffer_to_string(output, "it 'should pass current expectations' do", indentation_level + 1)
|
85
86
|
# collect all params
|
86
87
|
params_collection = []
|
87
88
|
mocks_collection = {}
|
@@ -111,13 +112,13 @@ module Pretentious
|
|
111
112
|
end
|
112
113
|
|
113
114
|
if params_collection.size > 0
|
114
|
-
deps = declare_dependencies(context, params_collection,
|
115
|
+
deps = declare_dependencies(context, params_collection, indentation_level + 2)
|
115
116
|
buffer_inline_to_string(output, deps) if deps != ''
|
116
117
|
end
|
117
118
|
|
118
119
|
if mocks_collection.keys.size > 0
|
119
120
|
buffer_to_string(output, generate_rspec_stub(context, mocks_collection,
|
120
|
-
|
121
|
+
(indentation_level + 2) * @_indentation.length))
|
121
122
|
end
|
122
123
|
|
123
124
|
expectations = []
|
@@ -132,13 +133,13 @@ module Pretentious
|
|
132
133
|
''
|
133
134
|
end
|
134
135
|
|
135
|
-
buffer_to_string(str, "# #{context_prefix}#{k} #{params_desc_str} should return #{context.value_of(block[:result])}",
|
136
|
-
buffer_inline_to_string(str, generate_expectation(context, fixture, k, block[:params], block[:block], block[:result]))
|
136
|
+
buffer_to_string(str, "# #{context_prefix}#{k} #{params_desc_str} should return #{context.value_of(block[:result])}", indentation_level + 2)
|
137
|
+
buffer_inline_to_string(str, generate_expectation(indentation_level, context, fixture, k, block[:params], block[:block], block[:result]))
|
137
138
|
expectations << str unless expectations.include? str
|
138
139
|
end
|
139
140
|
end
|
140
141
|
buffer_inline_to_string(output, expectations.join("\n"))
|
141
|
-
buffer_to_string(output, 'end',
|
142
|
+
buffer_to_string(output, 'end', indentation_level + 1)
|
142
143
|
output
|
143
144
|
end
|
144
145
|
|
@@ -167,8 +168,8 @@ module Pretentious
|
|
167
168
|
'be_nil'
|
168
169
|
elsif result.is_a? Exception
|
169
170
|
'raise_error'
|
170
|
-
elsif context.
|
171
|
-
"eq(#{context.
|
171
|
+
elsif context.map_name result.object_id
|
172
|
+
"eq(#{context.map_name(result.object_id)})"
|
172
173
|
else
|
173
174
|
"eq(#{Pretentious.value_ize(Pretentious::Context.new, result)})"
|
174
175
|
end
|
data/lib/pretentious/version.rb
CHANGED
data/run_test.sh
CHANGED
@@ -14,25 +14,24 @@ RSpec.describe Fibonacci do
|
|
14
14
|
n_3 = 4
|
15
15
|
n_4 = 5
|
16
16
|
# Fibonacci#fib when passed n = 1 should return 1
|
17
|
-
expect(@fixture.fib(n)).to eq(
|
17
|
+
expect(@fixture.fib(n)).to eq(n)
|
18
18
|
|
19
19
|
# Fibonacci#fib when passed n = 2 should return 1
|
20
|
-
expect(@fixture.fib(n_1)).to eq(
|
20
|
+
expect(@fixture.fib(n_1)).to eq(n)
|
21
21
|
|
22
22
|
# Fibonacci#fib when passed n = 3 should return 2
|
23
|
-
expect(@fixture.fib(n_2)).to eq(
|
23
|
+
expect(@fixture.fib(n_2)).to eq(n_1)
|
24
24
|
|
25
25
|
# Fibonacci#fib when passed n = 4 should return 3
|
26
|
-
expect(@fixture.fib(n_3)).to eq(
|
26
|
+
expect(@fixture.fib(n_3)).to eq(n_2)
|
27
27
|
|
28
28
|
# Fibonacci#fib when passed n = 5 should return 5
|
29
|
-
expect(@fixture.fib(n_4)).to eq(
|
29
|
+
expect(@fixture.fib(n_4)).to eq(n_4)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
33
|
+
it 'should pass current expectations' do
|
34
|
+
# Fibonacci::say_hello should return 'hello'
|
35
|
+
expect(Fibonacci.say_hello).to eq('hello')
|
36
|
+
end
|
37
|
+
end
|
data/spec/generated/m_d5_spec.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
RSpec.describe Digest::MD5 do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
it 'should pass current expectations' do
|
6
|
+
sample = 'This is the digest'
|
7
|
+
# Digest::MD5::hexdigest when passed "This is the digest" should return '9f12248dcddeda976611d192efaaf72a'
|
8
|
+
expect(Digest::MD5.hexdigest(sample)).to eq('9f12248dcddeda976611d192efaaf72a')
|
9
|
+
end
|
10
|
+
end
|
@@ -54,7 +54,7 @@ RSpec.describe TestClass1 do
|
|
54
54
|
|
55
55
|
it 'should pass current expectations' do
|
56
56
|
another_object = TestClass1.new('test')
|
57
|
-
# TestClass1#return_self when passed message = #<TestClass1:
|
57
|
+
# TestClass1#return_self when passed message = #<TestClass1:0x000000012813a0> should return another_object
|
58
58
|
expect(@fixture.return_self(another_object)).to eq(another_object)
|
59
59
|
end
|
60
60
|
end
|
@@ -70,5 +70,4 @@ RSpec.describe TestClass1 do
|
|
70
70
|
expect(@fixture.message).to eq(@message)
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
74
|
-
end
|
73
|
+
end
|
@@ -31,8 +31,7 @@ RSpec.describe TestClass2 do
|
|
31
31
|
|
32
32
|
it 'should pass current expectations' do
|
33
33
|
# TestClass2#test when passed object = "This is message 3" should return 'This is message 3'
|
34
|
-
expect(@fixture.test(@message2)).to eq(
|
34
|
+
expect(@fixture.test(@message2)).to eq(@message2)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
end
|
37
|
+
end
|
@@ -13,8 +13,7 @@ RSpec.describe TestClassForAutoStub do
|
|
13
13
|
allow_any_instance_of(AnotherClassUsedByTestClass).to receive(:get_message).and_return('HI THERE!!!!')
|
14
14
|
|
15
15
|
# TestClassForAutoStub#method_that_uses_the_class_to_stub should return ["Hello Glorious world", "HI THERE!!!!"]
|
16
|
-
expect(@fixture.method_that_uses_the_class_to_stub).to eq(
|
16
|
+
expect(@fixture.method_that_uses_the_class_to_stub).to eq(a)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
end
|
@@ -13,13 +13,13 @@ RSpec.describe TestClassForMocks do
|
|
13
13
|
allow_any_instance_of(TestMockSubClass).to receive(:increment_val).and_return(2, 3, 4, 5)
|
14
14
|
|
15
15
|
# TestClassForMocks#method_with_assign= when passed params2 = "test" should return 'test'
|
16
|
-
expect(@fixture.method_with_assign=('test')).to eq('test')
|
16
|
+
expect(@fixture.method_with_assign = ('test')).to eq('test')
|
17
17
|
|
18
18
|
# TestClassForMocks#method_with_usage should return 'a return string'
|
19
19
|
expect(@fixture.method_with_usage).to eq('a return string')
|
20
20
|
|
21
21
|
# TestClassForMocks#method_with_usage2 should return [2, 3, 4, 5]
|
22
|
-
expect(@fixture.method_with_usage2).to eq(
|
22
|
+
expect(@fixture.method_with_usage2).to eq(a)
|
23
23
|
|
24
24
|
# TestClassForMocks#method_with_usage4 should return 'a return string'
|
25
25
|
expect(@fixture.method_with_usage4).to eq('a return string')
|
@@ -39,5 +39,4 @@ RSpec.describe TestClassForMocks do
|
|
39
39
|
expect(@fixture.method_with_usage3('a message')).to eq(a)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
end
|
42
|
+
end
|
data/spec/generator_spec.rb
CHANGED
@@ -35,6 +35,12 @@ class DummyGenerator
|
|
35
35
|
@data << {begin: test_class}
|
36
36
|
end
|
37
37
|
|
38
|
+
def body(instances)
|
39
|
+
instances.each_with_index do |instance, num|
|
40
|
+
generate(instance, num + 1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
38
44
|
def generate(test_instance, instance_count)
|
39
45
|
@data << {instance: test_instance.class.to_s,
|
40
46
|
instance_method_calls: test_instance.method_calls,
|
@@ -55,13 +61,18 @@ class DummyGenerator2
|
|
55
61
|
|
56
62
|
def initialize
|
57
63
|
@data = []
|
58
|
-
|
59
64
|
end
|
60
65
|
|
61
66
|
def begin_spec(test_class)
|
62
67
|
@data << {begin: test_class}
|
63
68
|
end
|
64
69
|
|
70
|
+
def body(instances)
|
71
|
+
instances.each_with_index do |instance, num|
|
72
|
+
generate(instance, num + 1)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
65
76
|
def generate(test_instance, instance_count)
|
66
77
|
@data << {generate: test_instance.class.to_s, instance_count: instance_count}
|
67
78
|
|
@@ -18,10 +18,8 @@ RSpec.describe Pretentious::Generator do
|
|
18
18
|
result = Pretentious::Generator.generate_for(Fibonacci) do
|
19
19
|
Fibonacci.say_hello
|
20
20
|
end
|
21
|
-
expect(result).to eq(Fibonacci => { output:"# This file was automatically generated by the pretentious gem\nrequire 'minitest_helper'\nrequire
|
21
|
+
expect(result).to eq(Fibonacci => { output: "# This file was automatically generated by the pretentious gem\nrequire 'minitest_helper'\nrequire 'minitest/autorun'\n\nclass FibonacciTest < Minitest::Test\nend\n\nclass FibonacciScenario1 < FibonacciTest\n def test_current_expectation\n # Fibonacci::say_hello should return 'hello'\n assert_equal 'hello', Fibonacci.say_hello\n end\nend",
|
22
22
|
generator: Pretentious::MinitestGenerator })
|
23
23
|
end
|
24
|
-
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
data/spec/prententious_spec.rb
CHANGED
@@ -13,7 +13,7 @@ RSpec.describe Pretentious::Generator do
|
|
13
13
|
object = TestClass1.new(message)
|
14
14
|
object.return_self(message)
|
15
15
|
end
|
16
|
-
expect(call_artifacts[TestClass1][:output]).to eq("# This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe TestClass1 do\n context 'Scenario 1' do\n before do\n @message = { test: 'message' }\n @fixture = TestClass1.new(@message)\n end\n\n it 'should pass current expectations' do\n # TestClass1#return_self when passed message = {:test=>\"message\"} should return @message\n expect(@fixture.return_self(@message)).to eq(@message)\n end\n end\
|
16
|
+
expect(call_artifacts[TestClass1][:output]).to eq("# This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe TestClass1 do\n context 'Scenario 1' do\n before do\n @message = { test: 'message' }\n @fixture = TestClass1.new(@message)\n end\n\n it 'should pass current expectations' do\n # TestClass1#return_self when passed message = {:test=>\"message\"} should return @message\n expect(@fixture.return_self(@message)).to eq(@message)\n end\n end\nend")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "classes should have a stub class section" do
|
@@ -36,7 +36,7 @@ RSpec.describe Pretentious::Generator do
|
|
36
36
|
expect(fib.fib(6)).to eq(8)
|
37
37
|
|
38
38
|
expect(result).to eq(
|
39
|
-
Fibonacci => { output: "# This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe Fibonacci do\n
|
39
|
+
Fibonacci => { output: "# This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe Fibonacci do\n it 'should pass current expectations' do\n # Fibonacci::say_hello should return 'hello'\n expect(Fibonacci.say_hello).to eq('hello')\n end\nend",
|
40
40
|
generator: Pretentious::RspecGenerator })
|
41
41
|
end
|
42
42
|
end
|
@@ -90,7 +90,7 @@ RSpec.describe Pretentious::Generator do
|
|
90
90
|
it 'declare watched classes beforehand and capture when certain methods are invoked' do
|
91
91
|
# declare intention
|
92
92
|
Pretentious.on(TestClass5).method_called(:test_method).spec_for(Fibonacci) do |results|
|
93
|
-
expect(results[Fibonacci][:output]).to eq("# This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe Fibonacci do\n context 'Scenario 1' do\n before do\n @fixture = Fibonacci.new\n end\n\n it 'should pass current expectations' do\n # Fibonacci#fib when passed n = 5 should return 5\n expect(@fixture.fib(5)).to eq(5)\n end\n end\
|
93
|
+
expect(results[Fibonacci][:output]).to eq("# This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe Fibonacci do\n context 'Scenario 1' do\n before do\n @fixture = Fibonacci.new\n end\n\n it 'should pass current expectations' do\n # Fibonacci#fib when passed n = 5 should return 5\n expect(@fixture.fib(5)).to eq(5)\n end\n end\nend")
|
94
94
|
end
|
95
95
|
|
96
96
|
expect(Pretentious::Generator).to receive(:generate_for).with(Fibonacci).and_call_original
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class FibonacciTest < Minitest::Test
|
6
6
|
end
|
@@ -35,5 +35,4 @@ class FibonacciScenario2 < FibonacciTest
|
|
35
35
|
# Fibonacci::say_hello should return 'hello'
|
36
36
|
assert_equal 'hello', Fibonacci.say_hello
|
37
37
|
end
|
38
|
-
|
39
|
-
end
|
38
|
+
end
|
data/test/generated/test_m_d5.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class Digest::MD5Test < Minitest::Test
|
6
6
|
end
|
@@ -12,5 +12,4 @@ class Digest::MD5Scenario1 < Digest::MD5Test
|
|
12
12
|
# Digest::MD5::hexdigest when passed "This is the digest" should return '9f12248dcddeda976611d192efaaf72a'
|
13
13
|
assert_equal '9f12248dcddeda976611d192efaaf72a', Digest::MD5.hexdigest(sample)
|
14
14
|
end
|
15
|
-
|
16
|
-
end
|
15
|
+
end
|
data/test/generated/test_meme.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class MemeTest < Minitest::Test
|
6
6
|
end
|
@@ -17,5 +17,4 @@ class MemeScenario1 < MemeTest
|
|
17
17
|
# Meme#will_it_blend? should return 'YES!'
|
18
18
|
assert_equal 'YES!', @fixture.will_it_blend?
|
19
19
|
end
|
20
|
-
end
|
21
|
-
|
20
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class TestClass1Test < Minitest::Test
|
6
6
|
end
|
@@ -61,7 +61,7 @@ class TestClass1Scenario3 < TestClass1Test
|
|
61
61
|
def test_current_expectation
|
62
62
|
another_object = TestClass1.new('test')
|
63
63
|
|
64
|
-
# TestClass1#return_self when passed message = #<TestClass1:
|
64
|
+
# TestClass1#return_self when passed message = #<TestClass1:0x000000010f3808> should return another_object
|
65
65
|
assert_equal another_object, @fixture.return_self(another_object)
|
66
66
|
end
|
67
67
|
end
|
@@ -76,5 +76,4 @@ class TestClass1Scenario4 < TestClass1Test
|
|
76
76
|
# TestClass1#message should return @message
|
77
77
|
assert_equal @message, @fixture.message
|
78
78
|
end
|
79
|
-
end
|
80
|
-
|
79
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class TestClass2Test < Minitest::Test
|
6
6
|
end
|
@@ -38,5 +38,4 @@ class TestClass2Scenario3 < TestClass2Test
|
|
38
38
|
# TestClass2#test when passed object = "This is message 3" should return 'This is message 3'
|
39
39
|
assert_equal 'This is message 3', @fixture.test(@message2)
|
40
40
|
end
|
41
|
-
end
|
42
|
-
|
41
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class TestClass3Test < Minitest::Test
|
6
6
|
end
|
@@ -33,5 +33,4 @@ class TestClass3Scenario2 < TestClass3Test
|
|
33
33
|
# TestClass3#show_messages should return 'awesome!!!'
|
34
34
|
assert_equal 'awesome!!!', @fixture.show_messages
|
35
35
|
end
|
36
|
-
end
|
37
|
-
|
36
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class TestClass4Test < Minitest::Test
|
6
6
|
end
|
@@ -17,5 +17,4 @@ class TestClass4Scenario1 < TestClass4Test
|
|
17
17
|
|
18
18
|
def test_current_expectation
|
19
19
|
end
|
20
|
-
end
|
21
|
-
|
20
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was automatically generated by the pretentious gem
|
2
2
|
require 'minitest_helper'
|
3
|
-
require
|
3
|
+
require 'minitest/autorun'
|
4
4
|
|
5
5
|
class TestClassForMocksTest < Minitest::Test
|
6
6
|
end
|
@@ -16,7 +16,7 @@ class TestClassForMocksScenario1 < TestClassForMocksTest
|
|
16
16
|
TestMockSubClass.stub_any_instance(:test_method, 'a return string') do
|
17
17
|
TestMockSubClass.stub_any_instance(:increment_val, 2) do
|
18
18
|
# TestClassForMocks#method_with_assign= when passed params2 = "test" should return 'test'
|
19
|
-
assert_equal 'test', @fixture.method_with_assign=('test')
|
19
|
+
assert_equal 'test', @fixture.method_with_assign = ('test')
|
20
20
|
|
21
21
|
# TestClassForMocks#method_with_usage should return 'a return string'
|
22
22
|
assert_equal 'a return string', @fixture.method_with_usage
|
@@ -46,5 +46,4 @@ class TestClassForMocksScenario2 < TestClassForMocksTest
|
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
49
|
-
end
|
50
|
-
|
49
|
+
end
|
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.1.
|
4
|
+
version: 0.1.11
|
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-12-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|