pretentious 0.1.6 → 0.1.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.
@@ -1,5 +1,8 @@
1
1
  module Pretentious
2
+ # The trigger class is used for hooking into an existing method
3
+ # in order to record the usage of a target class
2
4
  class Trigger
5
+ # options that ca be passed to a trigger
3
6
  class Options
4
7
  attr_accessor :output_folder
5
8
  end
@@ -38,9 +41,7 @@ module Pretentious
38
41
  FileUtils.mkdir_p output_folder
39
42
  result[:generator].helper(output_folder)
40
43
  filename = result[:generator].naming(output_folder, klass)
41
- File.open(filename, 'w') {
42
- |f| f.write(result[:output])
43
- }
44
+ File.open(filename, 'w') { |f| f.write(result[:output]) }
44
45
  filename
45
46
  end
46
47
 
@@ -48,55 +49,54 @@ module Pretentious
48
49
 
49
50
  def attach_generator(generator, target, method, spec_classes, results_block, options)
50
51
  target.send(:define_method, method.to_sym) do |*args, &block|
51
- result = nil
52
- Pretentious::Generator.test_generator = generator
53
- generator_result = Pretentious::Generator.generate_for(*spec_classes) do
54
- result = send(:"_pretentious_orig_#{method}", *args, &block)
55
- end
52
+ result = nil
53
+ Pretentious::Generator.test_generator = generator
54
+ generator_result = Pretentious::Generator.generate_for(*spec_classes) do
55
+ result = send(:"_pretentious_orig_#{method}", *args, &block)
56
+ end
56
57
 
57
- results_block.call(generator_result, options) if results_block
58
+ results_block.call(generator_result, options) if results_block
58
59
 
59
- result
60
- end
60
+ result
61
+ end
61
62
  end
62
63
 
63
64
  def install_trigger
64
65
  @options = Pretentious::Trigger::Options.new
65
66
 
66
- default_callback = Proc.new { |result_per_generator, options|
67
+ default_callback = proc do |result_per_generator, options|
67
68
  output_files = []
68
- result_per_generator.each { |klass, result|
69
+ result_per_generator.each do |klass, result|
69
70
  output_folder = result[:generator].location(options.output_folder)
70
- filename = Pretentious::Trigger::output_file(result, klass, output_folder)
71
+ filename = Pretentious::Trigger.output_file(result, klass, output_folder)
71
72
  output_files << filename
72
- }
73
+ end
73
74
  output_files
74
- }
75
+ end
75
76
 
76
77
  @results_block = default_callback unless @results_block
77
78
 
78
- @target_methods.each { |method|
79
- @target_class.class_exec(@target_class, method) do |klass, m|
80
-
81
- if !klass.instance_methods.include? :"_pretentious_orig_#{m}"
82
- alias_method :"_pretentious_orig_#{m}", :"#{m}"
83
- end
84
-
79
+ @target_methods.each do |method|
80
+ @target_class.class_exec(@target_class, method) do |klass, m|
81
+ unless klass.instance_methods.include? :"_pretentious_orig_#{m}"
82
+ alias_method :"_pretentious_orig_#{m}", :"#{m}"
85
83
  end
84
+ end
86
85
 
87
- attach_generator(@generator, @target_class, method, @spec_classes, @results_block, @options)
88
- }
86
+ attach_generator(@generator, @target_class, method, @spec_classes, @results_block, @options)
87
+ end
89
88
 
90
- @target_class_methods.each { |method|
89
+ @target_class_methods.each do |method|
91
90
  @target_class.singleton_class.class_exec(@target_class, method) do |klass, m|
92
- if !klass.methods.include? :"_pretentious_orig_#{m}"
91
+ unless klass.methods.include? :"_pretentious_orig_#{m}"
93
92
  alias_method :"_pretentious_orig_#{m}", :"#{m}"
94
93
  end
95
94
  end
96
- attach_generator(@generator, @target_class.singleton_class, method, @spec_classes, @results_block, @options)
97
- }
95
+ attach_generator(@generator, @target_class.singleton_class, method,
96
+ @spec_classes, @results_block, @options)
97
+ end
98
98
 
99
99
  @options
100
100
  end
101
101
  end
102
- end
102
+ end
@@ -1,3 +1,4 @@
1
+ # Pretentious - version
1
2
  module Pretentious
2
- VERSION = "0.1.6"
3
+ VERSION = '0.1.7'
3
4
  end
data/pretentious.gemspec CHANGED
@@ -24,4 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "minitest", "~> 5.7"
25
25
  spec.add_development_dependency "minitest-stub_any_instance", "~> 1.0"
26
26
  spec.add_development_dependency "awesome_print"
27
+ spec.add_development_dependency "rubocop", "~> 0.35"
28
+ spec.add_development_dependency "rspec_junit_formatter", '0.2.2'
29
+ spec.add_development_dependency "simplecov"
27
30
  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.6.gem
5
+ gem install pretentious-0.1.7.gem
6
6
  ruby test/test_generator.rb
@@ -1,60 +1,76 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Pretentious::Deconstructor do
4
-
5
4
  before do
6
5
  @fixture = Pretentious::Deconstructor.new
7
6
  end
8
7
 
9
8
  describe "#build_tree" do
10
-
11
9
  it "should decompose an object" do
12
-
13
10
  message = "test"
14
11
  another_object = Pretentious.watch {
15
12
  TestClass1.new(message)
16
13
  }
17
14
 
18
15
  # 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,
21
- :composition=>"test"}],
22
- :params_types=>[[:req, :message]]})
16
+ expect(@fixture.build_tree(another_object)).to eq(class: TestClass1,
17
+ id: another_object.object_id,
18
+ composition: [{ class: String,
19
+ id: message.object_id,
20
+ composition: "test"}],
21
+ params_types: [[:req, :message]])
23
22
 
24
23
  end
25
-
26
24
  end
27
25
 
28
26
  describe "Object#_deconstruct_to_ruby" do
29
27
  it "generates the ruby code to create an object" do
30
- output = Pretentious.watch {
28
+ output = Pretentious.watch do
31
29
  a = "Some type of string"
32
30
  a._deconstruct_to_ruby
33
- }
34
- expect(output).to eq("a = \"Some type of string\"\n")
31
+ end
32
+ expect(output).to eq("a = 'Some type of string'\n")
33
+ end
34
+
35
+ it "deconstructs arrays types" do
36
+ output = Pretentious.watch do
37
+ hash = { message: "hello" }
38
+ arr = [1, 2, 3, "hello", hash, ['subarray', 2, :symbol]]
39
+ test_class = TestClass1.new(arr)
40
+ test_class._deconstruct_to_ruby
41
+ end
42
+ expect(output).to eq("message = [1, 2, 3, 'hello', { message: 'hello' }, ['subarray', 2, :symbol]]\ntest_class = TestClass1.new(message)\n")
43
+ end
44
+
45
+ it "deconstructs hash types" do
46
+ output = Pretentious.watch do
47
+ hash = { message: "hello", arr: [1, 2, 3], hash: { message2: "msg" } }
48
+ test_class = TestClass1.new(hash)
49
+ test_class._deconstruct_to_ruby
50
+ end
51
+ expect(output).to eq("message = { message: 'hello', arr: [1, 2, 3], hash: { message2: 'msg' } }\ntest_class = TestClass1.new(message)\n")
35
52
  end
36
53
 
37
54
  it "deconstruct multiple objects" do
38
- output = Pretentious.watch {
55
+ output = Pretentious.watch do
39
56
  a = "Some type of string"
40
57
  b = TestClass1.new("Hello world")
41
58
  test_class = TestClass3.new(a, b)
42
59
  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")
60
+ end
61
+ expect(output).to eq("testclass2 = TestClass1.new('Hello world')\ntest_class = TestClass3.new('Some type of string', testclass2)\n")
45
62
  end
46
63
  end
47
64
 
48
65
  describe "#deconstruct" do
49
-
50
66
  it "should build list of variables to declare" do
51
67
  message = "test"
52
- another_object = Pretentious.watch {
68
+ another_object = Pretentious.watch do
53
69
  TestClass1.new(message)
54
- }
70
+ end
55
71
 
56
72
  decons = @fixture.deconstruct([], another_object)
57
- expect( decons ).to eq({declaration:
73
+ expect(decons).to eq({declaration:
58
74
  [{id: message.object_id,
59
75
  class: String,
60
76
  value: "test",
@@ -73,7 +89,5 @@ RSpec.describe Pretentious::Deconstructor do
73
89
  :ref=>[{:id=>message.object_id,
74
90
  :class=>String, :value=>"test", :used_by=>:inline}]}}})
75
91
  end
76
-
77
92
  end
78
-
79
93
  end
@@ -1,45 +1,38 @@
1
- #This file was automatically generated by the pretentious gem
1
+ # This file was automatically generated by the pretentious gem
2
2
  require 'spec_helper'
3
3
 
4
4
  RSpec.describe Fibonacci do
5
-
6
5
  context 'Scenario 1' do
7
6
  before do
8
7
  @fixture = Fibonacci.new
9
8
  end
10
9
 
11
10
  it 'should pass current expectations' do
12
-
13
11
  n = 1
14
12
  n_1 = 2
15
13
  n_2 = 3
16
14
  n_3 = 4
17
15
  n_4 = 5
18
-
19
16
  # Fibonacci#fib when passed n = 1 should return 1
20
- expect( @fixture.fib(n) ).to eq(1)
17
+ expect(@fixture.fib(n)).to eq(1)
21
18
 
22
19
  # Fibonacci#fib when passed n = 2 should return 1
23
- expect( @fixture.fib(n_1) ).to eq(1)
20
+ expect(@fixture.fib(n_1)).to eq(1)
24
21
 
25
22
  # Fibonacci#fib when passed n = 3 should return 2
26
- expect( @fixture.fib(n_2) ).to eq(2)
23
+ expect(@fixture.fib(n_2)).to eq(2)
27
24
 
28
25
  # Fibonacci#fib when passed n = 4 should return 3
29
- expect( @fixture.fib(n_3) ).to eq(3)
26
+ expect(@fixture.fib(n_3)).to eq(3)
30
27
 
31
28
  # Fibonacci#fib when passed n = 5 should return 5
32
- expect( @fixture.fib(n_4) ).to eq(5)
33
-
29
+ expect(@fixture.fib(n_4)).to eq(5)
34
30
  end
35
-
36
31
  end
37
32
 
38
33
  it 'should pass current expectations' do
39
-
40
34
  # Fibonacci::say_hello should return hello
41
- expect( Fibonacci.say_hello ).to eq("hello")
42
-
35
+ expect(Fibonacci.say_hello).to eq('hello')
43
36
  end
44
37
 
45
38
  end
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  class TestClass
10
10
 
11
- def initialize
11
+ def initialize(dep = nil)
12
12
  @test_class2 = TestSubClass.new
13
13
  end
14
14
 
data/spec/m_d5_spec.rb CHANGED
@@ -1,15 +1,11 @@
1
- #This file was automatically generated by the pretentious gem
1
+ # This file was automatically generated by the pretentious gem
2
2
  require 'spec_helper'
3
3
 
4
4
  RSpec.describe Digest::MD5 do
5
-
6
5
  it 'should pass current expectations' do
7
-
8
- sample = "This is the digest"
9
-
6
+ sample = 'This is the digest'
10
7
  # Digest::MD5::hexdigest when passed "This is the digest" should return 9f12248dcddeda976611d192efaaf72a
11
- expect( Digest::MD5.hexdigest(sample) ).to eq("9f12248dcddeda976611d192efaaf72a")
12
-
8
+ expect(Digest::MD5.hexdigest(sample)).to eq('9f12248dcddeda976611d192efaaf72a')
13
9
  end
14
10
 
15
11
  end
@@ -18,8 +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 \"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\n\n end\n\nend\n",
22
- generator: Pretentious::MinitestGenerator }})
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\n end\n\nend\n",
22
+ generator: Pretentious::MinitestGenerator })
23
23
  end
24
24
 
25
25
  end
@@ -9,6 +9,16 @@ RSpec.describe Pretentious::Generator do
9
9
  Pretentious::Generator.test_generator = Pretentious::RspecGenerator
10
10
  end
11
11
 
12
+
13
+ it "uses instance variables when used both in test and in fixtures" do
14
+ call_artifacts = Pretentious::Generator.generate_for(TestClass1) do
15
+ message = {test: "message"}
16
+ object = TestClass1.new(message)
17
+ object.return_self(message)
18
+ end
19
+ 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 {:test=>\"message\"}\n expect(@fixture.return_self(@message)).to eq(@message)\n end\n end\n\nend\n")
20
+ end
21
+
12
22
  it "classes should have a stub class section" do
13
23
  Fibonacci._stub(String)
14
24
  expect(Fibonacci._get_mock_classes).to eq([String])
@@ -28,9 +38,9 @@ RSpec.describe Pretentious::Generator do
28
38
  fib = Fibonacci.new
29
39
  expect(fib.fib(6)).to eq(8)
30
40
 
31
- expect(result).to eq({
32
- 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\n\nend\n",
33
- generator: Pretentious::RspecGenerator}})
41
+ expect(result).to eq(
42
+ 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\n\nend\n",
43
+ generator: Pretentious::RspecGenerator })
34
44
  end
35
45
  end
36
46
 
@@ -38,7 +48,7 @@ RSpec.describe Pretentious::Generator do
38
48
  it "declare watched classes beforehand and capture when certain methods are invoked" do
39
49
  #declare intention
40
50
  Pretentious.on(TestClass5).method_called(:test_method).spec_for(Fibonacci) do |results|
41
- expect(results[Fibonacci][:output]).to eq("#This file was automatically generated by the pretentious gem\nrequire 'spec_helper'\n\nRSpec.describe Fibonacci do\n\n context 'Scenario 1' do\n before do\n @fixture = Fibonacci.new\n end\n\n it 'should pass current expectations' do\n\n # Fibonacci#fib when passed n = 5 should return 5\n expect( @fixture.fib(5) ).to eq(5)\n\n end\n\n end\n\nend\n")
51
+ 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\n\nend\n")
42
52
  end
43
53
 
44
54
  expect(Pretentious::Generator).to receive(:generate_for).with(Fibonacci).and_call_original
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
- require 'pretentious'
1
+ require 'simplecov'
2
2
  require 'awesome_print'
3
3
  require_relative '../test_classes'
4
+ SimpleCov.start
5
+ require 'pretentious'
@@ -1,92 +1,77 @@
1
- #This file was automatically generated by the pretentious gem
1
+ # This file was automatically generated by the pretentious gem
2
2
  require 'spec_helper'
3
3
 
4
4
  RSpec.describe TestClass1 do
5
-
6
5
  context 'Scenario 1' do
7
6
  before do
8
- @fixture = TestClass1.new("test")
7
+ @fixture = TestClass1.new('test')
9
8
  end
10
9
 
11
10
  it 'should pass current expectations' do
12
-
13
11
  # TestClass1#message should return test
14
- expect( @fixture.message ).to eq("test")
15
-
12
+ expect(@fixture.message).to eq('test')
16
13
  end
17
-
18
14
  end
19
15
 
20
16
  context 'Scenario 2' do
21
17
  before do
22
- @another_object = TestClass1.new("test")
23
- @message = {hello: "world", test: @another_object, arr_1: [1, 2, 3, 4, 5, @another_object], sub_hash: {yes: true, obj: @another_object}}
18
+ @another_object = TestClass1.new('test')
19
+ @message = { hello: 'world', test: @another_object, arr_1: [1, 2, 3, 4, 5, @another_object], sub_hash: { yes: true, obj: @another_object } }
24
20
  @fixture = TestClass1.new(@message)
25
21
  end
26
22
 
27
23
  it 'should pass current expectations' do
28
-
29
- var_2169524400 = Proc.new { |message|
30
- @message
24
+ var_14407380 = proc { |message|
25
+ @message
31
26
  }
32
27
 
33
28
  test_class1 = nil
34
- var_2169511140 = Proc.new {
35
- # Variable return values ... can't figure out what goes in here...
29
+ var_14401180 = proc {
30
+ # Variable return values ... can't figure out what goes in here...
36
31
  }
37
32
 
38
-
39
33
  # TestClass1#print_message should return
40
- expect( @fixture.print_message ).to be_nil
34
+ expect(@fixture.print_message).to be_nil
41
35
 
42
36
  # TestClass1#print_message should return
43
- expect( @fixture.print_message ).to be_nil
37
+ expect(@fixture.print_message).to be_nil
44
38
 
45
- # TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000102a00f98@example.rb:73>
46
- expect( @fixture.set_block &var_2169524400 ).to eq(var_2169524400)
39
+ # TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000001b78030@example.rb:73>
40
+ expect(@fixture.set_block &var_14407380).to eq(var_14407380)
47
41
 
48
- # TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x00000101db0950 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2163049820=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000101db0950 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2163049820=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000101db0950 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={2163049820=>"message"}>}}
49
- expect( @fixture.call_block &var_2169511140 ).to eq(@message)
42
+ # TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x00000001bab818 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={14507340=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000001bab818 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={14507340=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000001bab818 @message="test", @_init_arguments={:params=>["test"], :params_types=>[[:req, :message]]}, @_variable_names={14507340=>"message"}>}}
43
+ expect(@fixture.call_block &var_14401180).to eq(@message)
50
44
 
51
45
  # TestClass1#something_is_wrong should return StandardError
52
46
  expect { @fixture.something_is_wrong }.to raise_error
53
47
 
54
48
  # TestClass1#just_returns_true should return true
55
- expect( @fixture.just_returns_true ).to be true
56
-
49
+ expect(@fixture.just_returns_true).to be true
57
50
  end
58
-
59
51
  end
60
52
 
61
53
  context 'Scenario 3' do
62
54
  before do
63
- @fixture = TestClass1.new("Hello")
55
+ @fixture = TestClass1.new('Hello')
64
56
  end
65
57
 
66
58
  it 'should pass current expectations' do
67
-
68
- another_object = TestClass1.new("test")
69
-
70
- # TestClass1#return_self when passed message = #<TestClass1:0x00000101db0950> should return #<TestClass1:0x00000101db0950>
71
- expect( @fixture.return_self(another_object) ).to eq(another_object)
72
-
59
+ another_object = TestClass1.new('test')
60
+ # TestClass1#return_self when passed message = #<TestClass1:0x00000001bab818> should return #<TestClass1:0x00000001bab818>
61
+ expect(@fixture.return_self(another_object)).to eq(another_object)
73
62
  end
74
-
75
63
  end
76
64
 
77
65
  context 'Scenario 4' do
78
66
  before do
79
- @message = TestClass1.new("test")
67
+ @message = TestClass1.new('test')
80
68
  @fixture = TestClass1.new(@message)
81
69
  end
82
70
 
83
71
  it 'should pass current expectations' do
84
-
85
- # TestClass1#message should return #<TestClass1:0x00000101db0950>
86
- expect( @fixture.message ).to eq(@message)
87
-
72
+ # TestClass1#message should return #<TestClass1:0x00000001bab818>
73
+ expect(@fixture.message).to eq(@message)
88
74
  end
89
-
90
75
  end
91
76
 
92
77
  end