pretentious 0.1.1 → 0.1.2

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: 8025fc11bf85286be01fb1bde220c64e7cc49c54
4
- data.tar.gz: ede071633cf959eb97125c7c173f445d406de366
3
+ metadata.gz: 2e52b4207be07ea0604174f928860a43de276e6d
4
+ data.tar.gz: 113710e58638b64cd72ce2c6c5ed8f74171440c2
5
5
  SHA512:
6
- metadata.gz: 2d02f840b1b06223fc6cfcd6df9a5552fe698a08815b4c7a0b86adfd83e539085fe27d1551d05aca9e9521801b6a56dc3f10333b9ce9793efdb76192e0f7ba04
7
- data.tar.gz: 6d73531a5d43c9b34d6094e10931c63d7feb0cf2efb1b884206bfc34cbf81d83d8a720e3203e1bdefa28586d9697ae9d836a6bd8297f981e6c0e5e1353e23d4d
6
+ metadata.gz: 3c3cf391ac3e937eb694d0362216a1f50d5c5603a7ee3a6f917067a7a96a26ec23a4f23a80b0f1a5492c32bf49b5962b338f41fdd8266dcb16f5fcfaeef206ad
7
+ data.tar.gz: bba29d6250c4da2835b94c65742473689a89eeef29ffeca71e1003ed60ea831071a0d2906125fc91ee103807b5564a04efc5d70b2e125b98a199a59d0e1786db
@@ -57,7 +57,6 @@ module Pretentious
57
57
 
58
58
  setup_instance(*args, &recordedProc)
59
59
  param_types = @_instance.method(:initialize).parameters
60
- puts "#{@_instance.class.name} params -> #{param_types.inspect}"
61
60
  @_instance_init[:params_types] = param_types
62
61
 
63
62
  @_method_calls = []
@@ -405,7 +404,7 @@ module Pretentious
405
404
  unless (block.nil?)
406
405
  @_init_arguments[:block] = RecordedProc.new(block) {}
407
406
  end
408
- @_variable_names= {}
407
+ @_variable_names = {}
409
408
 
410
409
  params = if (self.respond_to? :test_class )
411
410
  test_class.instance_method(:initialize).parameters
@@ -424,7 +423,7 @@ module Pretentious
424
423
  end
425
424
 
426
425
  def _variable_map
427
- @_variable_names
426
+ @_variable_names || {}
428
427
  end
429
428
 
430
429
  def _deconstruct
@@ -432,7 +431,20 @@ module Pretentious
432
431
  end
433
432
 
434
433
  def _deconstruct_to_ruby(var_name = nil, indentation = 0)
435
- Pretentious::Deconstructor.new().deconstruct_to_ruby(indentation, _variable_map.merge({self.object_id => var_name}), {}, [], self)
434
+ variable_names = {}
435
+
436
+ caller_context = binding.of_caller(1)
437
+ v_locals = caller_context.eval('local_variables')
438
+
439
+ v_locals.each { |v|
440
+ variable_value = caller_context.eval("#{v.to_s}")
441
+ if self.object_id == variable_value.object_id
442
+ variable_names[variable_value.object_id] = v
443
+ end
444
+ }
445
+
446
+ variable_names = _variable_map.merge({self.object_id => var_name}) unless var_name.nil?
447
+ Pretentious::Deconstructor.new().deconstruct_to_ruby(indentation, variable_names, {}, [], self)
436
448
  end
437
449
 
438
450
  end
@@ -1,3 +1,3 @@
1
1
  module Pretentious
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/run_test.sh CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  git add .
4
4
  gem build pretentious.gemspec
5
- gem install pretentious-0.1.0.gem
5
+ gem install pretentious-0.1.2.gem
6
6
  ruby test/test_generator.rb
@@ -22,6 +22,27 @@ RSpec.describe Pretentious::Deconstructor do
22
22
  :params_types=>[[:req, :message]]})
23
23
 
24
24
  end
25
+
26
+ end
27
+
28
+ describe "Object#_deconstruct_to_ruby" do
29
+ it "generates the ruby code to create an object" do
30
+ output = Pretentious.watch {
31
+ a = "Some type of string"
32
+ a._deconstruct_to_ruby
33
+ }
34
+ expect(output).to eq("a = \"Some type of string\"\n")
35
+ end
36
+
37
+ it "deconstruct multiple objects" do
38
+ output = Pretentious.watch {
39
+ a = "Some type of string"
40
+ b = TestClass1.new("Hello world")
41
+ test_class = TestClass3.new(a, b)
42
+ test_class._deconstruct_to_ruby
43
+ }
44
+ expect(output).to eq("testclass2 = TestClass1.new(\"Hello world\")\ntest_class = TestClass3.new(\"Some type of string\", testclass2)\n")
45
+ end
25
46
  end
26
47
 
27
48
  describe "#deconstruct" do
@@ -17,20 +17,20 @@ RSpec.describe TestClass1 do
17
17
 
18
18
  context 'Scenario 2' do
19
19
  before do
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}}
20
+ var_2167261360 = TestClass1.new("test")
21
+ message = {hello: "world", test: var_2167261360, arr_1: [1, 2, 3, 4, 5, var_2167261360], sub_hash: {yes: true, obj: var_2167261360}}
22
22
  @fixture = TestClass1.new(message)
23
23
  end
24
24
 
25
25
  it 'should pass current expectations' do
26
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
27
+ var_2167245200 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
28
+ var_2167127140 = Proc.new { |message|
29
+ var_2167245200
30
30
  }
31
31
 
32
32
  e = nil
33
- var_2168013120 = Proc.new {
33
+ var_2167121820 = Proc.new {
34
34
  # Variable return values ... can't figure out what goes in here...
35
35
  }
36
36
 
@@ -41,11 +41,11 @@ RSpec.describe TestClass1 do
41
41
  # TestClass1#print_message should return
42
42
  expect( @fixture.print_message ).to be_nil
43
43
 
44
- # TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000102728488@example.rb:73>
45
- expect( @fixture.set_block &var_2168018780 ).to eq(var_2168018780)
44
+ # TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000102575140@example.rb:73>
45
+ expect( @fixture.set_block &var_2167127140 ).to eq(var_2167127140)
46
46
 
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)
47
+ # TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x000001025b3f30 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2167261020=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x000001025b3f30 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2167261020=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x000001025b3f30 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2167261020=>"message"}>}}
48
+ expect( @fixture.call_block &var_2167121820 ).to eq(var_2167245200)
49
49
 
50
50
  # TestClass1#something_is_wrong should return StandardError
51
51
  expect { @fixture.something_is_wrong }.to raise_error
@@ -5,9 +5,9 @@ RSpec.describe TestClass3 do
5
5
 
6
6
  context 'Scenario 1' do
7
7
  before do
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)
8
+ var_2167261360 = TestClass1.new("test")
9
+ var_2167245200 = {hello: "world", test: var_2167261360, arr_1: [1, 2, 3, 4, 5, var_2167261360], sub_hash: {yes: true, obj: var_2167261360}}
10
+ testclass1 = TestClass1.new(var_2167245200)
11
11
  testclass2 = TestClass2.new("This is message 2", nil)
12
12
  @fixture = TestClass3.new(testclass1, testclass2)
13
13
  end
@@ -21,9 +21,9 @@ RSpec.describe TestClass3 do
21
21
 
22
22
  context 'Scenario 2' do
23
23
  before do
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)
24
+ var_2167261360 = TestClass1.new("test")
25
+ var_2167245200 = {hello: "world", test: var_2167261360, arr_1: [1, 2, 3, 4, 5, var_2167261360], sub_hash: {yes: true, obj: var_2167261360}}
26
+ testclass1 = TestClass1.new(var_2167245200)
27
27
  testclass2 = TestClass2.new("This is message 2", nil)
28
28
  @fixture = TestClass3.new(testclass1, testclass2)
29
29
  end
@@ -6,11 +6,11 @@ RSpec.describe TestClass4 do
6
6
  context 'Scenario 1' do
7
7
  before do
8
8
  var_8 = nil
9
- var_2168046320 = Proc.new {
9
+ var_2167163460 = Proc.new {
10
10
  # Variable return values ... can't figure out what goes in here...
11
11
  }
12
12
 
13
- @fixture = TestClass4.new(&var_2168046320)
13
+ @fixture = TestClass4.new(&var_2167163460)
14
14
  end
15
15
 
16
16
  it 'should pass current expectations' do
@@ -9,7 +9,7 @@ RSpec.describe TestClassForAutoStub do
9
9
  end
10
10
 
11
11
  it 'should pass current expectations' do
12
- var_2173998860 = ["Hello Glorious world", "HI THERE!!!!"]
12
+ var_2165345620 = ["Hello Glorious world", "HI THERE!!!!"]
13
13
 
14
14
  allow_any_instance_of(ClassUsedByTestClass).to receive(:stubbed_method).and_return("Hello Glorious world")
15
15
  allow_any_instance_of(AnotherClassUsedByTestClass).to receive(:get_message).and_return("HI THERE!!!!")
@@ -9,7 +9,7 @@ RSpec.describe TestClassForMocks do
9
9
  end
10
10
 
11
11
  it 'should pass current expectations' do
12
- var_2156635440 = [2, 3, 4, 5]
12
+ var_2165992020 = [2, 3, 4, 5]
13
13
 
14
14
  allow_any_instance_of(TestMockSubClass).to receive(:test_method).and_return("a return string")
15
15
  allow_any_instance_of(TestMockSubClass).to receive(:increment_val).and_return(2, 3, 4, 5)
@@ -35,12 +35,12 @@ RSpec.describe TestClassForMocks do
35
35
  end
36
36
 
37
37
  it 'should pass current expectations' do
38
- var_2167427940 = {val: 1, str: "hello world", message: "a message"}
38
+ var_2165878780 = {val: 1, str: "hello world", message: "a message"}
39
39
 
40
- allow_any_instance_of(TestMockSubClass).to receive(:return_hash).and_return(var_2167427940)
40
+ allow_any_instance_of(TestMockSubClass).to receive(:return_hash).and_return(var_2165878780)
41
41
 
42
42
  # TestClassForMocks#method_with_usage3 when passed message = "a message" should return {:val=>1, :str=>"hello world", :message=>"a message"}
43
- expect( @fixture.method_with_usage3("a message") ).to eq(var_2167427940)
43
+ expect( @fixture.method_with_usage3("a message") ).to eq(var_2165878780)
44
44
 
45
45
  end
46
46
  end
@@ -20,20 +20,20 @@ end
20
20
 
21
21
  class TestClass1Scenario2 < TestTestClass1
22
22
  def setup
23
- var_2167808880 = TestClass1.new("test")
24
- message = {hello: "world", test: var_2167808880, arr_1: [1, 2, 3, 4, 5, var_2167808880], sub_hash: {yes: true, obj: var_2167808880}}
23
+ var_2173943420 = TestClass1.new("test")
24
+ message = {hello: "world", test: var_2173943420, arr_1: [1, 2, 3, 4, 5, var_2173943420], sub_hash: {yes: true, obj: var_2173943420}}
25
25
  @fixture = TestClass1.new(message)
26
26
  end
27
27
 
28
28
  def test_current_expectation
29
29
  another_object = TestClass1.new("test")
30
- var_2167802520 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
31
- var_2167669280 = Proc.new { |message|
32
- var_2167802520
30
+ var_2172900980 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
31
+ var_2166428520 = Proc.new { |message|
32
+ var_2172900980
33
33
  }
34
34
 
35
35
  e = nil
36
- var_2161039260 = Proc.new {
36
+ var_2166393560 = Proc.new {
37
37
  # Variable return values ... can't figure out what goes in here...
38
38
  }
39
39
 
@@ -44,11 +44,11 @@ class TestClass1Scenario2 < TestTestClass1
44
44
  #TestClass1#print_message should return
45
45
  assert_nil @fixture.print_message
46
46
 
47
- #TestClass1#set_block should return #<Pretentious::RecordedProc:0x000001019d9980@example.rb:73>
48
- assert_equal var_2167669280, @fixture.set_block( &var_2167669280)
47
+ #TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000102412190@example.rb:73>
48
+ assert_equal var_2166428520, @fixture.set_block( &var_2166428520)
49
49
 
50
- #TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x000001026c45a0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2167808940=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x000001026c45a0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2167808940=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x000001026c45a0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2167808940=>"message"}>}}
51
- assert_equal var_2167802520, @fixture.call_block( &var_2161039260)
50
+ #TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x00000103277af0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2173943480=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000103277af0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2173943480=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000103277af0 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2173943480=>"message"}>}}
51
+ assert_equal var_2172900980, @fixture.call_block( &var_2166393560)
52
52
 
53
53
  #TestClass1#something_is_wrong should return StandardError
54
54
  assert_raises(StandardError) { @fixture.something_is_wrong }
@@ -7,9 +7,9 @@ end
7
7
 
8
8
  class TestClass3Scenario1 < TestTestClass3
9
9
  def setup
10
- var_2167808880 = TestClass1.new("test")
11
- var_2167802520 = {hello: "world", test: var_2167808880, arr_1: [1, 2, 3, 4, 5, var_2167808880], sub_hash: {yes: true, obj: var_2167808880}}
12
- testclass1 = TestClass1.new(var_2167802520)
10
+ var_2173943420 = TestClass1.new("test")
11
+ var_2172900980 = {hello: "world", test: var_2173943420, arr_1: [1, 2, 3, 4, 5, var_2173943420], sub_hash: {yes: true, obj: var_2173943420}}
12
+ testclass1 = TestClass1.new(var_2172900980)
13
13
  testclass2 = TestClass2.new("This is message 2", nil)
14
14
  @fixture = TestClass3.new(testclass1, testclass2)
15
15
  end
@@ -24,9 +24,9 @@ end
24
24
 
25
25
  class TestClass3Scenario2 < TestTestClass3
26
26
  def setup
27
- var_2167808880 = TestClass1.new("test")
28
- var_2167802520 = {hello: "world", test: var_2167808880, arr_1: [1, 2, 3, 4, 5, var_2167808880], sub_hash: {yes: true, obj: var_2167808880}}
29
- testclass1 = TestClass1.new(var_2167802520)
27
+ var_2173943420 = TestClass1.new("test")
28
+ var_2172900980 = {hello: "world", test: var_2173943420, arr_1: [1, 2, 3, 4, 5, var_2173943420], sub_hash: {yes: true, obj: var_2173943420}}
29
+ testclass1 = TestClass1.new(var_2172900980)
30
30
  testclass2 = TestClass2.new("This is message 2", nil)
31
31
  @fixture = TestClass3.new(testclass1, testclass2)
32
32
  end
@@ -8,11 +8,11 @@ end
8
8
  class TestClass4Scenario1 < TestTestClass4
9
9
  def setup
10
10
  var_8 = nil
11
- var_2167689280 = Proc.new {
11
+ var_2166489580 = Proc.new {
12
12
  # Variable return values ... can't figure out what goes in here...
13
13
  }
14
14
 
15
- @fixture = TestClass4.new(&var_2167689280)
15
+ @fixture = TestClass4.new(&var_2166489580)
16
16
  end
17
17
 
18
18
  def test_current_expectation
@@ -11,7 +11,7 @@ class TestClassForMocksScenario1 < TestTestClassForMocks
11
11
  end
12
12
 
13
13
  def test_current_expectation
14
- var_2174075580 = [2, 3, 4, 5]
14
+ var_2165696380 = [2, 3, 4, 5]
15
15
 
16
16
  TestMockSubClass.stub_any_instance(:test_method, "a return string") do
17
17
  TestMockSubClass.stub_any_instance(:increment_val, 2) do
@@ -39,11 +39,11 @@ class TestClassForMocksScenario2 < TestTestClassForMocks
39
39
  end
40
40
 
41
41
  def test_current_expectation
42
- var_2167328180 = {val: 1, str: "hello world", message: "a message"}
42
+ var_2165567200 = {val: 1, str: "hello world", message: "a message"}
43
43
 
44
- TestMockSubClass.stub_any_instance(:return_hash, var_2167328180) do
44
+ TestMockSubClass.stub_any_instance(:return_hash, var_2165567200) do
45
45
  #TestClassForMocks#method_with_usage3 when passed message = "a message" should return {:val=>1, :str=>"hello world", :message=>"a message"}
46
- assert_equal var_2167328180, @fixture.method_with_usage3("a message")
46
+ assert_equal var_2165567200, @fixture.method_with_usage3("a message")
47
47
 
48
48
  end
49
49
 
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.1
4
+ version: 0.1.2
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-29 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller