pretentious 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87f10781f0769264b1c39fa2c34463332546ba6a
4
- data.tar.gz: ffac481a78ad14c7f5bd62533f135b17aab304d9
3
+ metadata.gz: 711f7f3102783e3fc24a2b9044daed5cd1be70ff
4
+ data.tar.gz: c237cb52d65cbae1df165e094f25ca7a87f04231
5
5
  SHA512:
6
- metadata.gz: 54a6a2fdc2985b0920b61535f58dbfb4288315cc7c54f7d808dd68a587824a12b5f12aa0400c5fff508a23f537d259efc9e47b835e422856ac0c93f46b377ac4
7
- data.tar.gz: 0fc245c408de5c2f667e2c7d17d859f01aec59d54d12fa173e88a7d57b049fbdd7792843838e5a5ae65ea026d031aed92c579dbdb11209e76a4fbfa5b55224fd
6
+ metadata.gz: 1fc605179be58671aedfe0c45a5fa3b6f871901a1f04693e848ce8322e7baab69eba48313679e6147accd99a56cbfc32c10afa229e3ce5e9d9b213b8a5966aad
7
+ data.tar.gz: 12409641664626a1907833f66bda205457c17c132ab713b182926c5daf925258a4b4dbb360bbe537637335f9e9e465f85742360463df5405dea48316c71af79d
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/pretentious.svg)](https://badge.fury.io/rb/pretentious)
1
+ [![Gem Version](https://badge.fury.io/rb/pretentious.svg)](https://badge.fury.io/rb/pretentious) [![Circle CI](https://circleci.com/gh/jedld/pretentious/tree/master.svg?style=svg)](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 initialized are
314
- extracted from an object until only primitive types remain. The pretentious gem will also generate the
315
- necessary ruby code to create one form scracth. Below is an example:
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", "jclviste_test", nil, nil, 131074]
329
- config = {adapter: "mysql", encoding: "utf8", reconnect: false, database: "jclviste_test", pool: 5, username: "root", password: "password", host: "localhost"}
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
- ### How to use
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 using by the _deconstruct_to_ruby method.
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
- ### Using the Object deconstruct in rails
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 config.ru is sufficient to capture most objects:
386
+ For rails, including inside application.rb may be a good place to start:
374
387
 
375
388
  ```ruby
376
- #config.ru
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
- # ..... stuf ......
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 will fails to capture and as such those would not deconstruct properly.
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
@@ -1 +1,8 @@
1
+ require 'rspec/core/rake_task'
1
2
  require "bundler/gem_tasks"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
8
+ task :test => :spec
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
@@ -44,8 +44,9 @@ module Pretentious
44
44
 
45
45
  def self.watch(&block)
46
46
  Pretentious::Generator.watch_new_instances
47
- block.call
47
+ result = block.call
48
48
  Pretentious::Generator.unwatch_new_instances
49
+ result
49
50
  end
50
51
 
51
52
  class RecordedProc < Proc
@@ -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
- tree[:composition] = target_object
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
@@ -1,3 +1,3 @@
1
1
  module Pretentious
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/pretentious.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "binding_of_caller", "~> 0.7.2"
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
23
24
  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.0.6.gem
5
+ gem install pretentious-0.0.7.gem
6
6
  ruby test/test_generator.rb
@@ -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
@@ -1 +1,2 @@
1
+ require 'pretentious'
1
2
  require_relative '../test_classes'
@@ -22,25 +22,25 @@ RSpec.describe TestClass1 do
22
22
  context 'Scenario 2' do
23
23
  before do
24
24
 
25
- var_2161332560 = "test"
26
- another_object = TestClass1.new(var_2161332560)
27
- var_2161318440 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
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(var_2161318440)
29
+ @fixture = TestClass1.new(var_2157641020)
30
30
 
31
31
  end
32
32
 
33
33
  it 'should pass current expectations' do
34
34
 
35
- var_2161332560 = "test"
36
- another_object = TestClass1.new(var_2161332560)
37
- var_2161318440 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
38
- var_2161201340 = Proc.new { |message|
39
- var_2161318440
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
- var_2161188420 = Proc.new {
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:0x00000101a23eb8@example.rb:73>
55
- expect( @fixture.set_block &var_2161201340 ).to eq(var_2161201340)
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:0x00000101a6a110 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2161332560=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000101a6a110 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2161332560=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000101a6a110 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2161332560=>"message"}>}}
58
- expect( @fixture.call_block &var_2161188420 ).to eq(var_2161318440)
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
@@ -5,8 +5,8 @@ RSpec.describe TestClass3 do
5
5
  context 'Scenario 1' do
6
6
  before do
7
7
 
8
- var_2161332560 = "test"
9
- another_object = TestClass1.new(var_2161332560)
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
- var_2161332560 = "test"
32
- another_object = TestClass1.new(var_2161332560)
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"
@@ -5,13 +5,13 @@ RSpec.describe TestClass4 do
5
5
  context 'Scenario 1' do
6
6
  before do
7
7
 
8
- var_2161332560 = "test"
9
- var_2161220900 = Proc.new {
8
+ var_2157646020 = "test"
9
+ var_2157574220 = Proc.new {
10
10
  "test"
11
11
  }
12
12
 
13
13
 
14
- @fixture = TestClass4.new &var_2161220900
14
+ @fixture = TestClass4.new &var_2157574220
15
15
 
16
16
  end
17
17
 
@@ -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.6
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-02 00:00:00.000000000 Z
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