pretentious 0.1.0 → 0.1.1

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,3 +1,3 @@
1
1
  module Pretentious
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/pretentious.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.7"
25
25
  spec.add_development_dependency "minitest-stub_any_instance", "~> 1.0"
26
+ spec.add_development_dependency "awesome_print"
26
27
  end
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Pretentious::Deconstructor do
4
4
 
5
- context 'Pretentious::Deconstructor#build_tree' do
5
+ before do
6
+ @fixture = Pretentious::Deconstructor.new
7
+ end
6
8
 
7
- before do
8
- @fixture = Pretentious::Deconstructor.new
9
- end
9
+ describe "#build_tree" do
10
10
 
11
- it 'should decompose an object' do
11
+ it "should decompose an object" do
12
12
 
13
13
  message = "test"
14
14
  another_object = Pretentious.watch {
@@ -16,10 +16,43 @@ RSpec.describe Pretentious::Deconstructor do
16
16
  }
17
17
 
18
18
  # Pretentious::Deconstructor#build_tree when passed target_object = #<TestClass1:0x00000102d82860> should return {:class=>TestClass1, :id=>2171343920, :composition=>[{:class=>String, :id=>2171343600, :composition=>"test"}]}
19
- expect( @fixture.build_tree(another_object) ).to eq({class: TestClass1, id: another_object.object_id,
20
- composition: [{:class=>String, :id=>message.object_id, :composition=>"test"}]})
19
+ expect( @fixture.build_tree(another_object) ).to eq({:class=>TestClass1, :id=>another_object.object_id,
20
+ :composition=>[{:class=>String, :id=>message.object_id,
21
+ :composition=>"test"}],
22
+ :params_types=>[[:req, :message]]})
23
+
24
+ end
25
+ end
26
+
27
+ describe "#deconstruct" do
21
28
 
29
+ it "should build list of variables to declare" do
30
+ message = "test"
31
+ another_object = Pretentious.watch {
32
+ TestClass1.new(message)
33
+ }
34
+
35
+ decons = @fixture.deconstruct([], another_object)
36
+ expect( decons ).to eq({declaration:
37
+ [{id: message.object_id,
38
+ class: String,
39
+ value: "test",
40
+ :used_by=>:inline},
41
+ {id: another_object.object_id,
42
+ class: TestClass1,
43
+ params_types: [[:req, :message]],
44
+ used_by: [], ref: [{:id=>message.object_id,
45
+ :class=>String, value: "test", used_by: :inline}]}],
46
+ dependency: {message.object_id=>{:id=>message.object_id,
47
+ class: String, value: "test", used_by: :inline},
48
+ another_object.object_id=>{id: another_object.object_id,
49
+ :class=>TestClass1,
50
+ :params_types=>[[:req, :message]],
51
+ :used_by=>[],
52
+ :ref=>[{:id=>message.object_id,
53
+ :class=>String, :value=>"test", :used_by=>:inline}]}}})
22
54
  end
55
+
23
56
  end
24
57
 
25
58
  end
@@ -5,13 +5,10 @@ RSpec.describe Fibonacci do
5
5
 
6
6
  context 'Scenario 1' do
7
7
  before do
8
-
9
8
  @fixture = Fibonacci.new
10
-
11
9
  end
12
10
 
13
11
  it 'should pass current expectations' do
14
-
15
12
  n = 1
16
13
  n_1 = 2
17
14
  n_2 = 3
@@ -37,7 +34,6 @@ RSpec.describe Fibonacci do
37
34
  end
38
35
 
39
36
  it 'should pass current expectations' do
40
-
41
37
  # Fibonacci::say_hello should return hello
42
38
  expect( Fibonacci.say_hello ).to eq("hello")
43
39
 
@@ -51,6 +51,48 @@ class DummyGenerator
51
51
 
52
52
  end
53
53
 
54
+ class DummyGenerator2
55
+
56
+ def initialize
57
+ @data = []
58
+
59
+ end
60
+
61
+ def begin_spec(test_class)
62
+ @data << {begin: test_class}
63
+ end
64
+
65
+ def generate(test_instance, instance_count)
66
+ @data << {generate: test_instance.class.to_s, instance_count: instance_count}
67
+
68
+ deconstructor = Pretentious::Deconstructor.new
69
+
70
+ deconstruct_targets = [test_instance]
71
+ test_instance.method_calls.each do |method_calls|
72
+ deconstruct_targets = deconstruct_targets + method_calls[:params]
73
+ end
74
+
75
+ deconstruct = deconstructor.deconstruct(test_instance.method_calls, *deconstruct_targets)
76
+ deconstruct[:declaration].each do |d|
77
+ @data << d
78
+ end
79
+
80
+ test_instance.method_calls.each do |method_calls|
81
+ @data << method_calls
82
+ end
83
+ @data << :generate_end
84
+ end
85
+
86
+ def end_spec()
87
+ @data << :end
88
+ end
89
+
90
+ def output
91
+ @data
92
+ end
93
+
94
+ end
95
+
54
96
  RSpec.describe Pretentious::Generator do
55
97
 
56
98
  context 'Pretentious::Generator#impostor_for' do
@@ -143,6 +185,33 @@ RSpec.describe Pretentious::Generator do
143
185
  :class=>TestSubClass}]}, :result=>"a return string"}],
144
186
  :instance_count=>1}, :end], generator: DummyGenerator}})
145
187
  end
188
+
189
+
190
+ end
191
+ end
192
+
193
+ context "reference optimization" do
194
+
195
+ around(:each) do |example|
196
+ Pretentious::Generator.test_generator= DummyGenerator2
197
+ example.run
198
+ Pretentious::Generator.test_generator= nil
199
+ end
200
+
201
+ it "removes unused variables" do
202
+
203
+ call_artifacts = Pretentious::Generator.generate_for(TestClass3) do
204
+ message = "test"
205
+ another_object = TestClass1.new(message)
206
+ test_class_one = TestClass1.new({hello: "world", test: another_object, arr_1: [1,2,3,4,5, another_object],
207
+ sub_hash: {yes: true, obj: another_object}})
208
+ test_class_two = TestClass2.new("This is message 2", message)
209
+
210
+ class_to_test = TestClass3.new(test_class_one, test_class_two)
211
+ class_to_test.show_messages
212
+ class_to_test.change_message(message)
213
+ end
146
214
  end
215
+
147
216
  end
148
217
  end
data/spec/m_d5_spec.rb CHANGED
@@ -4,7 +4,6 @@ require 'spec_helper'
4
4
  RSpec.describe Digest::MD5 do
5
5
 
6
6
  it 'should pass current expectations' do
7
-
8
7
  sample = "This is the digest"
9
8
 
10
9
  # Digest::MD5::hexdigest when passed "This is the digest" should return 9f12248dcddeda976611d192efaaf72a
@@ -18,7 +18,7 @@ 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 \"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\n end\n",
21
+ expect(result).to eq({Fibonacci =>{output: "#This file was automatically generated by the pretentious gem\nrequire 'minitest_helper'\nrequire \"minitest/autorun\"\n\nclass TestFibonacci < Minitest::Test\nend\n\n def test_current_expectation\n #Fibonacci::say_hello should return hello\n assert_equal \"hello\", Fibonacci.say_hello\n\n\n end\n",
22
22
  generator: Pretentious::MinitestGenerator }})
23
23
  end
24
24
 
@@ -19,7 +19,7 @@ RSpec.describe Pretentious::Generator do
19
19
  Fibonacci.say_hello
20
20
  end
21
21
  expect(result).to eq({
22
- Fibonacci =>{output: "#This file was automatically generated by the pretentious gem\nrequire '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
+ Fibonacci =>{output: "#This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe Fibonacci do\n\n it 'should pass current expectations' do\n # Fibonacci::say_hello should return hello\n expect( Fibonacci.say_hello ).to eq(\"hello\")\n\n end\nend\n",
23
23
  generator: Pretentious::RspecGenerator}})
24
24
  end
25
25
 
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'pretentious'
2
- require_relative '../test_classes'
2
+ require 'awesome_print'
3
+ require_relative '../test_classes'
@@ -1,17 +1,14 @@
1
+ #This file was automatically generated by the pretentious gem
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe TestClass1 do
4
5
 
5
6
  context 'Scenario 1' do
6
7
  before do
7
-
8
-
9
8
  @fixture = TestClass1.new("test")
10
-
11
9
  end
12
10
 
13
11
  it 'should pass current expectations' do
14
-
15
12
  # TestClass1#message should return test
16
13
  expect( @fixture.message ).to eq("test")
17
14
 
@@ -20,26 +17,20 @@ RSpec.describe TestClass1 do
20
17
 
21
18
  context 'Scenario 2' do
22
19
  before do
23
-
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
-
28
- @fixture = TestClass1.new(var_2157430640)
29
-
20
+ var_2168149380 = TestClass1.new("test")
21
+ message = {hello: "world", test: var_2168149380, arr_1: [1, 2, 3, 4, 5, var_2168149380], sub_hash: {yes: true, obj: var_2168149380}}
22
+ @fixture = TestClass1.new(message)
30
23
  end
31
24
 
32
25
  it 'should pass current expectations' do
33
-
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
26
+ another_object = TestClass1.new("test")
27
+ var_2168135220 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
28
+ var_2168018780 = Proc.new { |message|
29
+ var_2168135220
39
30
  }
40
31
 
41
32
  e = nil
42
- var_2173948680 = Proc.new {
33
+ var_2168013120 = Proc.new {
43
34
  # Variable return values ... can't figure out what goes in here...
44
35
  }
45
36
 
@@ -50,11 +41,11 @@ RSpec.describe TestClass1 do
50
41
  # TestClass1#print_message should return
51
42
  expect( @fixture.print_message ).to be_nil
52
43
 
53
- # TestClass1#set_block should return #<Pretentious::RecordedProc:0x0000010327a868@example.rb:71>
54
- expect( @fixture.set_block &var_2157617620 ).to eq(var_2157617620)
44
+ # TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000102728488@example.rb:73>
45
+ expect( @fixture.set_block &var_2168018780 ).to eq(var_2168018780)
55
46
 
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)
47
+ # TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x0000010276a9a0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2168149420=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x0000010276a9a0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2168149420=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x0000010276a9a0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2168149420=>"message"}>}}
48
+ expect( @fixture.call_block &var_2168013120 ).to eq(var_2168135220)
58
49
 
59
50
  # TestClass1#something_is_wrong should return StandardError
60
51
  expect { @fixture.something_is_wrong }.to raise_error
@@ -1,17 +1,14 @@
1
+ #This file was automatically generated by the pretentious gem
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe TestClass2 do
4
5
 
5
6
  context 'Scenario 1' do
6
7
  before do
7
-
8
-
9
- @fixture = TestClass2.new("This is message 2")
10
-
8
+ @fixture = TestClass2.new("This is message 2", nil)
11
9
  end
12
10
 
13
11
  it 'should pass current expectations' do
14
-
15
12
  # TestClass2#print_message should return
16
13
  expect( @fixture.print_message ).to be_nil
17
14
 
@@ -21,4 +18,29 @@ RSpec.describe TestClass2 do
21
18
  end
22
19
  end
23
20
 
21
+ context 'Scenario 2' do
22
+ before do
23
+ @fixture = TestClass2.new("This is message 3", nil)
24
+ end
25
+
26
+ it 'should pass current expectations' do
27
+ end
28
+ end
29
+
30
+ context 'Scenario 3' do
31
+ before do
32
+ message2 = "This is message 3"
33
+ message = TestClass2.new(message2, nil)
34
+ @fixture = TestClass2.new(message, message2)
35
+ end
36
+
37
+ it 'should pass current expectations' do
38
+ message3 = "This is message 3"
39
+
40
+ # TestClass2#test when passed object = "This is message 3" should return This is message 3
41
+ expect( @fixture.test(message3) ).to eq("This is message 3")
42
+
43
+ end
44
+ end
45
+
24
46
  end
@@ -1,23 +1,18 @@
1
+ #This file was automatically generated by the pretentious gem
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe TestClass3 do
4
5
 
5
6
  context 'Scenario 1' do
6
7
  before do
7
-
8
- var_2157436060 = "test"
9
- another_object = TestClass1.new(var_2157436060)
10
- args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
11
- test_class_one = TestClass1.new(args)
12
- args_1 = "This is message 2"
13
- test_class_two = TestClass2.new(args_1)
14
-
15
- @fixture = TestClass3.new(test_class_one, test_class_two)
16
-
8
+ var_2168149380 = TestClass1.new("test")
9
+ var_2168135220 = {hello: "world", test: var_2168149380, arr_1: [1, 2, 3, 4, 5, var_2168149380], sub_hash: {yes: true, obj: var_2168149380}}
10
+ testclass1 = TestClass1.new(var_2168135220)
11
+ testclass2 = TestClass2.new("This is message 2", nil)
12
+ @fixture = TestClass3.new(testclass1, testclass2)
17
13
  end
18
14
 
19
15
  it 'should pass current expectations' do
20
-
21
16
  # TestClass3#show_messages should return awesome!!!
22
17
  expect( @fixture.show_messages ).to eq("awesome!!!")
23
18
 
@@ -26,20 +21,14 @@ RSpec.describe TestClass3 do
26
21
 
27
22
  context 'Scenario 2' do
28
23
  before do
29
-
30
- var_2157436060 = "test"
31
- another_object = TestClass1.new(var_2157436060)
32
- args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
33
- test_class_one = TestClass1.new(args)
34
- args_1 = "This is message 2"
35
- test_class_two = TestClass2.new(args_1)
36
-
37
- @fixture = TestClass3.new(test_class_one, test_class_two)
38
-
24
+ var_2168149380 = TestClass1.new("test")
25
+ var_2168135220 = {hello: "world", test: var_2168149380, arr_1: [1, 2, 3, 4, 5, var_2168149380], sub_hash: {yes: true, obj: var_2168149380}}
26
+ testclass1 = TestClass1.new(var_2168135220)
27
+ testclass2 = TestClass2.new("This is message 2", nil)
28
+ @fixture = TestClass3.new(testclass1, testclass2)
39
29
  end
40
30
 
41
31
  it 'should pass current expectations' do
42
-
43
32
  # TestClass3#show_messages should return awesome!!!
44
33
  expect( @fixture.show_messages ).to eq("awesome!!!")
45
34
 
@@ -1,22 +1,19 @@
1
+ #This file was automatically generated by the pretentious gem
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe TestClass4 do
4
5
 
5
6
  context 'Scenario 1' do
6
7
  before do
7
-
8
- var_2157436060 = "test"
9
- var_2157471500 = Proc.new {
10
- "test"
8
+ var_8 = nil
9
+ var_2168046320 = Proc.new {
10
+ # Variable return values ... can't figure out what goes in here...
11
11
  }
12
12
 
13
-
14
- @fixture = TestClass4.new &var_2157471500
15
-
13
+ @fixture = TestClass4.new(&var_2168046320)
16
14
  end
17
15
 
18
16
  it 'should pass current expectations' do
19
-
20
17
  end
21
18
  end
22
19
 
@@ -5,14 +5,11 @@ RSpec.describe TestClassForAutoStub do
5
5
 
6
6
  context 'Scenario 1' do
7
7
  before do
8
-
9
8
  @fixture = TestClassForAutoStub.new
10
-
11
9
  end
12
10
 
13
11
  it 'should pass current expectations' do
14
-
15
- var_2173901020 = ["Hello Glorious world", "HI THERE!!!!"]
12
+ var_2173998860 = ["Hello Glorious world", "HI THERE!!!!"]
16
13
 
17
14
  allow_any_instance_of(ClassUsedByTestClass).to receive(:stubbed_method).and_return("Hello Glorious world")
18
15
  allow_any_instance_of(AnotherClassUsedByTestClass).to receive(:get_message).and_return("HI THERE!!!!")
@@ -1,17 +1,15 @@
1
+ #This file was automatically generated by the pretentious gem
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe TestClassForMocks do
4
5
 
5
6
  context 'Scenario 1' do
6
7
  before do
7
-
8
8
  @fixture = TestClassForMocks.new
9
-
10
9
  end
11
10
 
12
11
  it 'should pass current expectations' do
13
-
14
- var_2166690320 = [2, 3, 4, 5]
12
+ var_2156635440 = [2, 3, 4, 5]
15
13
 
16
14
  allow_any_instance_of(TestMockSubClass).to receive(:test_method).and_return("a return string")
17
15
  allow_any_instance_of(TestMockSubClass).to receive(:increment_val).and_return(2, 3, 4, 5)
@@ -33,19 +31,16 @@ RSpec.describe TestClassForMocks do
33
31
 
34
32
  context 'Scenario 2' do
35
33
  before do
36
-
37
34
  @fixture = TestClassForMocks.new
38
-
39
35
  end
40
36
 
41
37
  it 'should pass current expectations' do
38
+ var_2167427940 = {val: 1, str: "hello world", message: "a message"}
42
39
 
43
- var_2166592900 = {val: 1, str: "hello world", message: "a message"}
44
-
45
- allow_any_instance_of(TestMockSubClass).to receive(:return_hash).and_return(var_2166592900)
40
+ allow_any_instance_of(TestMockSubClass).to receive(:return_hash).and_return(var_2167427940)
46
41
 
47
42
  # 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_2166592900)
43
+ expect( @fixture.method_with_usage3("a message") ).to eq(var_2167427940)
49
44
 
50
45
  end
51
46
  end