pretentious 0.0.6 → 0.0.7
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/README.md +30 -16
- data/Rakefile +7 -0
- data/example.rb +6 -1
- data/lib/pretentious.rb +2 -1
- data/lib/pretentious/deconstructor.rb +19 -3
- data/lib/pretentious/version.rb +1 -1
- data/pretentious.gemspec +1 -0
- data/run_test.sh +1 -1
- data/spec/deconstructor_spec.rb +25 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/test_class1_spec.rb +14 -14
- data/spec/test_class3_spec.rb +4 -4
- data/spec/test_class4_spec.rb +3 -3
- data/test/test_generator.rb +3 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711f7f3102783e3fc24a2b9044daed5cd1be70ff
|
4
|
+
data.tar.gz: c237cb52d65cbae1df165e094f25ca7a87f04231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fc605179be58671aedfe0c45a5fa3b6f871901a1f04693e848ce8322e7baab69eba48313679e6147accd99a56cbfc32c10afa229e3ce5e9d9b213b8a5966aad
|
7
|
+
data.tar.gz: 12409641664626a1907833f66bda205457c17c132ab713b182926c5daf925258a4b4dbb360bbe537637335f9e9e465f85742360463df5405dea48316c71af79d
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](https://badge.fury.io/rb/pretentious)
|
1
|
+
[](https://badge.fury.io/rb/pretentious) [](https://circleci.com/gh/jedld/pretentious/tree/master)
|
2
2
|
|
3
3
|
# Ruby::Pretentious
|
4
4
|
|
@@ -12,6 +12,19 @@ for various frameworks. It is also useful for "recording" current behavior of ex
|
|
12
12
|
to prepare for refactoring. As a bonus it also exposes an Object Deconstructor which allows you, given
|
13
13
|
any object, to obtain a ruby code on how it was created.
|
14
14
|
|
15
|
+
|
16
|
+
## Table of Contents
|
17
|
+
|
18
|
+
1. [Installation](#installation)
|
19
|
+
2. [Usage](#usage)
|
20
|
+
3. [Handling complex parameters and object constructors](#handling-complex-parameters-and-object-constructors)
|
21
|
+
4. [Capturing Exceptions](#capturing-exceptions)
|
22
|
+
5. [Object Deconstruction Utility](#object-deconstruction-utility)
|
23
|
+
1. [Using the Object deconstructor in rails](#using-the-object-deconstructor-in-rails)
|
24
|
+
6. [Things to do after](#things-to-do-after)
|
25
|
+
7. [Limitations](#limitations)
|
26
|
+
|
27
|
+
|
15
28
|
## Installation
|
16
29
|
|
17
30
|
Add this line to your application's Gemfile:
|
@@ -96,7 +109,6 @@ For this example place the following into spec_helper.rb:
|
|
96
109
|
|
97
110
|
```ruby
|
98
111
|
#inside spec_helper.rb
|
99
|
-
|
100
112
|
class Fibonacci
|
101
113
|
|
102
114
|
def fib(n)
|
@@ -310,9 +322,9 @@ should generate the following in rspec
|
|
310
322
|
## Object Deconstruction Utility
|
311
323
|
|
312
324
|
As Pretentious as the gem is, there are other uses other than generating tests specs. Tools are also available to
|
313
|
-
deconstruct objects. Object deconstruction basically means that the components used to create and
|
314
|
-
extracted
|
315
|
-
necessary ruby code to create one
|
325
|
+
deconstruct objects. Object deconstruction basically means that the components used to create and initialize an object
|
326
|
+
are extracted and decomposed until only primitive types remain. The pretentious gem will also generate the
|
327
|
+
necessary ruby code to create one from scratch. Below is an example:
|
316
328
|
|
317
329
|
Given an instance of an activerecord base connection for example
|
318
330
|
|
@@ -325,8 +337,8 @@ running deconstruct would generate:
|
|
325
337
|
```ruby
|
326
338
|
var_70301267513280 = #<File:0x007fe094279f80>
|
327
339
|
logger = ActiveSupport::Logger.new(var_70301267513280)
|
328
|
-
connection_options = ["localhost", "root", "password", "
|
329
|
-
config = {adapter: "mysql", encoding: "utf8", reconnect: false, database: "
|
340
|
+
connection_options = ["localhost", "root", "password", "test_db", nil, nil, 131074]
|
341
|
+
config = {adapter: "mysql", encoding: "utf8", reconnect: false, database: "test_db", pool: 5, username: "root", password: "password", host: "localhost"}
|
330
342
|
var_70301281665660 = ActiveRecord::ConnectionAdapters::MysqlAdapter.new(connection, logger, connection_options, config)
|
331
343
|
```
|
332
344
|
Note that
|
@@ -337,7 +349,7 @@ var_70301267513280 = #<File:0x007fe094279f80>
|
|
337
349
|
|
338
350
|
because the pretentious gem was not able to capture its init arguments.
|
339
351
|
|
340
|
-
|
352
|
+
## How to use
|
341
353
|
|
342
354
|
Simply call:
|
343
355
|
|
@@ -349,10 +361,11 @@ before all your objects are initalized. This will add the following methods to a
|
|
349
361
|
object._deconstruct
|
350
362
|
object._deconstruct_to_ruby
|
351
363
|
```
|
352
|
-
The _deconstruct method generates a raw deconstruction data structure
|
364
|
+
The _deconstruct method generates a raw deconstruction data structure used by the _deconstruct_to_ruby method.
|
365
|
+
|
353
366
|
Of course _deconstruct_to_ruby generates the ruby code necessary to create the object!
|
354
367
|
|
355
|
-
|
368
|
+
## Using the Object deconstructor in rails
|
356
369
|
|
357
370
|
In your Gemfile, add the pretentious gem.
|
358
371
|
|
@@ -370,10 +383,10 @@ The do a bundle
|
|
370
383
|
Note: It is advisable to add it only in the test or development group!
|
371
384
|
The way it logs objects would probably prevent anything from being GC'ed.
|
372
385
|
|
373
|
-
For rails, including inside
|
386
|
+
For rails, including inside application.rb may be a good place to start:
|
374
387
|
|
375
388
|
```ruby
|
376
|
-
#
|
389
|
+
#application.rb
|
377
390
|
require File.expand_path('../boot', __FILE__)
|
378
391
|
|
379
392
|
require 'rails/all'
|
@@ -381,14 +394,14 @@ require 'rails/all'
|
|
381
394
|
# you've limited to :test, :development, or :production.
|
382
395
|
Bundler.require(*Rails.groups)
|
383
396
|
|
384
|
-
if Rails.env.test?
|
397
|
+
if Rails.env.test? || Rails.env.development?
|
385
398
|
puts "watching new instances"
|
386
399
|
Pretentious::Generator.watch_new_instances
|
387
400
|
end
|
388
401
|
|
389
402
|
module App
|
390
403
|
class Application < Rails::Application
|
391
|
-
# .....
|
404
|
+
# ..... stuff ......
|
392
405
|
|
393
406
|
end
|
394
407
|
end
|
@@ -423,7 +436,8 @@ var_70301339518120 = User::ActiveRecord_Relation.new(klass, table)
|
|
423
436
|
2.2.0 :007 >
|
424
437
|
```
|
425
438
|
|
426
|
-
Note: There are some objects it
|
439
|
+
Note: There are some objects it may fail to deconstruct properly because of certain [limitations](#limitations) or it
|
440
|
+
may have failed to capture object creation early enough.
|
427
441
|
|
428
442
|
|
429
443
|
## Things to do after
|
@@ -439,7 +453,7 @@ a bdd'er/tdd'er.
|
|
439
453
|
Computers are bad at mind reading (for now) and they don't really know your expectation of "correctness", as such
|
440
454
|
it assumes your code is correct and can only use equality based matchers. It can also only reliably match
|
441
455
|
primitive data types, hashes, Procs and arrays to a degree. More complex expectations are unfortunately left for the humans
|
442
|
-
to resolve.
|
456
|
+
to resolve. This is expected to improve in future versions of the pretentious gem.
|
443
457
|
|
444
458
|
Procs that return a constant value will be resolved properly. However variable return values are currently still
|
445
459
|
not generated properly will return a stub (future versions may use sourcify to resolve Procs for ruby 1.9)
|
data/Rakefile
CHANGED
data/example.rb
CHANGED
@@ -18,7 +18,6 @@ Pretentious.spec_for(Fibonacci) do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
Pretentious.spec_for(TestClass1, TestClass2, TestClass3, TestClass4) do
|
21
|
-
|
22
21
|
another_object = TestClass1.new("test")
|
23
22
|
test_class_one = TestClass1.new({hello: "world", test: another_object, arr_1: [1,2,3,4,5, another_object],
|
24
23
|
sub_hash: {yes: true, obj: another_object}})
|
@@ -55,3 +54,9 @@ Pretentious.spec_for(Digest::MD5) do
|
|
55
54
|
sample = "This is the digest"
|
56
55
|
Digest::MD5.hexdigest(sample)
|
57
56
|
end
|
57
|
+
|
58
|
+
#Pretentious.spec_for(Pretentious::Deconstructor) do
|
59
|
+
# deconstructor = Pretentious::Deconstructor.new
|
60
|
+
# another_object = TestClass1.new("test")
|
61
|
+
# deconstructor.build_tree(another_object)
|
62
|
+
#end
|
data/lib/pretentious.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
class Pretentious::Deconstructor
|
2
2
|
|
3
|
+
class UnResolved
|
4
|
+
|
5
|
+
attr_accessor :target_object
|
6
|
+
|
7
|
+
def initialize(object)
|
8
|
+
@target_object = object
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
class Reference
|
4
13
|
attr_accessor :tree
|
5
14
|
|
@@ -97,7 +106,6 @@ class Pretentious::Deconstructor
|
|
97
106
|
|
98
107
|
#creates a tree on how the object was created
|
99
108
|
def build_tree(target_object)
|
100
|
-
|
101
109
|
tree = {class: get_test_class(target_object), id: target_object.object_id, composition: []}
|
102
110
|
if (target_object.is_a? Array)
|
103
111
|
tree[:composition] = deconstruct_array(target_object)
|
@@ -120,7 +128,13 @@ class Pretentious::Deconstructor
|
|
120
128
|
|
121
129
|
tree[:block] = build_tree(args[:block]) unless args[:block].nil?
|
122
130
|
else
|
123
|
-
|
131
|
+
if (self.class.is_primitive?(target_object))
|
132
|
+
tree[:composition] = target_object
|
133
|
+
elsif (target_object.class == File)
|
134
|
+
tree[:composition] << build_tree(target_object.path)
|
135
|
+
else
|
136
|
+
tree[:composition] = UnResolved.new(target_object)
|
137
|
+
end
|
124
138
|
end
|
125
139
|
|
126
140
|
else
|
@@ -167,7 +181,7 @@ class Pretentious::Deconstructor
|
|
167
181
|
|
168
182
|
def self.is_primitive?(value)
|
169
183
|
value.is_a?(String) || value.is_a?(Fixnum) || value.is_a?(TrueClass) || value.is_a?(FalseClass) ||
|
170
|
-
value.is_a?(NilClass) || value.is_a?(Symbol)
|
184
|
+
value.is_a?(NilClass) || value.is_a?(Symbol) || value.is_a?(Class)
|
171
185
|
end
|
172
186
|
|
173
187
|
def self.block_param_names(proc)
|
@@ -345,6 +359,8 @@ class Pretentious::Deconstructor
|
|
345
359
|
output_hash(definition[:value], variable_map, declared_names)
|
346
360
|
elsif (definition[:value].is_a? Array)
|
347
361
|
output_array(definition[:value], variable_map, declared_names)
|
362
|
+
elsif (definition[:value].is_a? UnResolved)
|
363
|
+
'nil #parameters unresolvable. cannot decompose'
|
348
364
|
else
|
349
365
|
Pretentious::value_ize(definition[:value], variable_map, declared_names)
|
350
366
|
end
|
data/lib/pretentious/version.rb
CHANGED
data/pretentious.gemspec
CHANGED
data/run_test.sh
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pretentious::Deconstructor do
|
4
|
+
|
5
|
+
context 'Pretentious::Deconstructor#build_tree' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@fixture = Pretentious::Deconstructor.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should decompose an object' do
|
12
|
+
|
13
|
+
message = "test"
|
14
|
+
another_object = Pretentious.watch {
|
15
|
+
TestClass1.new(message)
|
16
|
+
}
|
17
|
+
|
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"}]})
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/test_class1_spec.rb
CHANGED
@@ -22,25 +22,25 @@ RSpec.describe TestClass1 do
|
|
22
22
|
context 'Scenario 2' do
|
23
23
|
before do
|
24
24
|
|
25
|
-
|
26
|
-
another_object = TestClass1.new(
|
27
|
-
|
25
|
+
var_2157646020 = "test"
|
26
|
+
another_object = TestClass1.new(var_2157646020)
|
27
|
+
var_2157641020 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
28
28
|
|
29
|
-
@fixture = TestClass1.new(
|
29
|
+
@fixture = TestClass1.new(var_2157641020)
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should pass current expectations' do
|
34
34
|
|
35
|
-
|
36
|
-
another_object = TestClass1.new(
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
var_2157646020 = "test"
|
36
|
+
another_object = TestClass1.new(var_2157646020)
|
37
|
+
var_2157641020 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
38
|
+
var_2157563100 = Proc.new { |message|
|
39
|
+
var_2157641020
|
40
40
|
}
|
41
41
|
|
42
42
|
e = nil
|
43
|
-
|
43
|
+
var_2157558520 = Proc.new {
|
44
44
|
# Variable return values ... can't figure out what goes in here...
|
45
45
|
}
|
46
46
|
|
@@ -51,11 +51,11 @@ RSpec.describe TestClass1 do
|
|
51
51
|
# TestClass1#print_message should return
|
52
52
|
expect( @fixture.print_message ).to be_nil
|
53
53
|
|
54
|
-
# TestClass1#set_block should return #<Pretentious::RecordedProc:
|
55
|
-
expect( @fixture.set_block &
|
54
|
+
# TestClass1#set_block should return #<Pretentious::RecordedProc:0x000001013377d0@example.rb:71>
|
55
|
+
expect( @fixture.set_block &var_2157563100 ).to eq(var_2157563100)
|
56
56
|
|
57
|
-
# TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:
|
58
|
-
expect( @fixture.call_block &
|
57
|
+
# TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x00000101361f80 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2157646020=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000101361f80 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2157646020=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000101361f80 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2157646020=>"message"}>}}
|
58
|
+
expect( @fixture.call_block &var_2157558520 ).to eq(var_2157641020)
|
59
59
|
|
60
60
|
# TestClass1#something_is_wrong should return StandardError
|
61
61
|
expect { @fixture.something_is_wrong }.to raise_error
|
data/spec/test_class3_spec.rb
CHANGED
@@ -5,8 +5,8 @@ RSpec.describe TestClass3 do
|
|
5
5
|
context 'Scenario 1' do
|
6
6
|
before do
|
7
7
|
|
8
|
-
|
9
|
-
another_object = TestClass1.new(
|
8
|
+
var_2157646020 = "test"
|
9
|
+
another_object = TestClass1.new(var_2157646020)
|
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"
|
@@ -28,8 +28,8 @@ RSpec.describe TestClass3 do
|
|
28
28
|
context 'Scenario 2' do
|
29
29
|
before do
|
30
30
|
|
31
|
-
|
32
|
-
another_object = TestClass1.new(
|
31
|
+
var_2157646020 = "test"
|
32
|
+
another_object = TestClass1.new(var_2157646020)
|
33
33
|
args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
34
34
|
test_class_one = TestClass1.new(args)
|
35
35
|
args_1 = "This is message 2"
|
data/spec/test_class4_spec.rb
CHANGED
@@ -5,13 +5,13 @@ RSpec.describe TestClass4 do
|
|
5
5
|
context 'Scenario 1' do
|
6
6
|
before do
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
var_2157646020 = "test"
|
9
|
+
var_2157574220 = Proc.new {
|
10
10
|
"test"
|
11
11
|
}
|
12
12
|
|
13
13
|
|
14
|
-
@fixture = TestClass4.new &
|
14
|
+
@fixture = TestClass4.new &var_2157574220
|
15
15
|
|
16
16
|
end
|
17
17
|
|
data/test/test_generator.rb
CHANGED
@@ -132,7 +132,7 @@ end
|
|
132
132
|
#end
|
133
133
|
|
134
134
|
results_composition = Pretentious::Generator.generate_for(TestClass1, TestClass2, TestClass3) do
|
135
|
-
|
135
|
+
unresolvable = File.new("example.rb")
|
136
136
|
another_object = TestClass1.new("test")
|
137
137
|
test_class_one = TestClass1.new({hello: "world", test: another_object, arr_1: [1,2,3,4,5, another_object],
|
138
138
|
sub_hash: {yes: true, obj: another_object}})
|
@@ -149,7 +149,8 @@ results_composition = Pretentious::Generator.generate_for(TestClass1, TestClass2
|
|
149
149
|
}
|
150
150
|
|
151
151
|
test_class_one.call_block
|
152
|
-
|
152
|
+
test_class_one = TestClass1.new(unresolvable)
|
153
|
+
test_class_one.print_message
|
153
154
|
end
|
154
155
|
|
155
156
|
results_composition.each_value { |v| puts v}
|
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.
|
4
|
+
version: 0.0.7
|
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-
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Do you have a pretentious boss or dev lead that pushes you to embrace
|
56
70
|
tdd but for reasons hate it or them? here is a gem to deal with that.
|
57
71
|
email:
|
@@ -74,6 +88,7 @@ files:
|
|
74
88
|
- lib/pretentious/version.rb
|
75
89
|
- pretentious.gemspec
|
76
90
|
- run_test.sh
|
91
|
+
- spec/deconstructor_spec.rb
|
77
92
|
- spec/fibonacci_spec.rb
|
78
93
|
- spec/m_d5_spec.rb
|
79
94
|
- spec/spec_helper.rb
|
@@ -109,6 +124,7 @@ specification_version: 4
|
|
109
124
|
summary: Generate tests from existing code as well as a way to deal with pretentious
|
110
125
|
TDD/BDD developers
|
111
126
|
test_files:
|
127
|
+
- spec/deconstructor_spec.rb
|
112
128
|
- spec/fibonacci_spec.rb
|
113
129
|
- spec/m_d5_spec.rb
|
114
130
|
- spec/spec_helper.rb
|