code_driven_development 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/Rakefile +4 -2
- data/bin/cdd +11 -2
- data/code_driven_development.gemspec +2 -0
- data/features/my_feature.feature +9 -4
- data/lib/code_driven_development.rb +2 -19
- data/lib/code_driven_development/code_driven_development.rb +1 -2
- data/lib/code_driven_development/rule/method_call.rb +22 -0
- data/lib/code_driven_development/stubber/abstract_stubber.rb +39 -0
- data/lib/code_driven_development/stubber/const_stubber.rb +13 -0
- data/lib/code_driven_development/stubber/instance_method_stubber.rb +13 -0
- data/lib/code_driven_development/stubber/nested_call_stubber.rb +31 -0
- data/lib/code_driven_development/stubber/stubber.rb +22 -0
- data/lib/code_driven_development/test_component/context.rb +5 -2
- data/lib/code_driven_development/test_component/double.rb +13 -0
- data/lib/code_driven_development/version.rb +1 -1
- data/samples/president.rb +1 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/stubber_spec.rb +110 -0
- metadata +39 -6
- data/lib/code_driven_development/rule/constant_method_call.rb +0 -38
- data/lib/code_driven_development/rule/instance_method_call.rb +0 -38
- data/spec/samples/lone_sample.yaml +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9038114a834973a515c4328adb8cf027fcab116a
|
4
|
+
data.tar.gz: a5092ebdb605227e0f1262833289d0e08b01fc99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32b147b182e1f910937102822813e4ed2d6812e34fd89408fda80422da7744e16a32384000f71cec2742eae1907ec166290d4a9bc2ca3328835a2bc73ce24669
|
7
|
+
data.tar.gz: 7e0d462f9ac49184b3491c8940fe61bd800d0ba0e57a2af3721b9dc75fbbf19ef5a1d6df85bd759e0b424498d36e5bc64bc95438d9709be5bdff589e9d0610de
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ class Bunker < ActiveRecord::Base
|
|
9
9
|
validate :location, :protected => true
|
10
10
|
|
11
11
|
def alert_staff
|
12
|
+
staph.all_alert
|
12
13
|
Staff.alert_all
|
13
14
|
end
|
14
15
|
|
@@ -27,9 +28,19 @@ describe Bunker do
|
|
27
28
|
it { should validate_protected_of :location }
|
28
29
|
describe "#alert_staff" do
|
29
30
|
let(:obj) { described_class.new }
|
31
|
+
let(:all_alert) { double(:all_alert) }
|
32
|
+
let(:staph) { double(:staph) }
|
33
|
+
let(:alert_all) { double(:alert_all) }
|
30
34
|
subject { obj.alert_staff }
|
31
35
|
before do
|
32
|
-
allow(
|
36
|
+
allow(staph).to receive(:all_alert).and_return(all_alert)
|
37
|
+
allow(obj).to receive(:staph).and_return(staph)
|
38
|
+
allow(Staff).to receive(:alert_all).and_return(alert_all)
|
39
|
+
end
|
40
|
+
it "calls staph.all_alert" do
|
41
|
+
subject
|
42
|
+
expect(staph).to have_received :all_alert
|
43
|
+
expect(obj).to have_received :staph
|
33
44
|
end
|
34
45
|
it "calls Staff.alert_all" do
|
35
46
|
subject
|
@@ -38,9 +49,10 @@ describe Bunker do
|
|
38
49
|
end
|
39
50
|
describe "#alert_president" do
|
40
51
|
let(:obj) { described_class.new }
|
52
|
+
let(:stand_down) { double(:stand_down) }
|
41
53
|
subject { obj.alert_president }
|
42
54
|
before do
|
43
|
-
allow(SecretService).to receive
|
55
|
+
allow(SecretService).to receive(:stand_down).and_return(stand_down)
|
44
56
|
end
|
45
57
|
it "calls SecretService.stand_down" do
|
46
58
|
subject
|
data/Rakefile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
4
|
require 'cucumber/rake/task'
|
5
|
+
require 'rspec/core/rake_task'
|
5
6
|
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
8
|
Cucumber::Rake::Task.new
|
7
9
|
|
8
|
-
task default: :cucumber
|
10
|
+
task default: [:spec, :cucumber]
|
data/bin/cdd
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../lib/code_driven_development'
|
4
|
+
|
5
|
+
|
6
|
+
output = CodeDrivenDevelopment::CodeDrivenDevelopment.new(ARGF.read).test_code.strip
|
7
|
+
|
8
|
+
if STDOUT.tty?
|
9
|
+
require 'coderay'
|
10
|
+
puts CodeRay.scan(output, :ruby).term
|
11
|
+
else
|
12
|
+
puts output
|
13
|
+
end
|
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "ruby_parser"
|
22
|
+
spec.add_dependency "require_all"
|
23
|
+
spec.add_dependency "coderay"
|
22
24
|
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
26
|
spec.add_development_dependency "rake"
|
data/features/my_feature.feature
CHANGED
@@ -30,9 +30,10 @@ Feature: Creates awesome specs
|
|
30
30
|
"""ruby
|
31
31
|
describe "#i_call_things" do
|
32
32
|
let(:obj) { described_class.new }
|
33
|
+
let(:file_report) { double(:file_report) }
|
33
34
|
subject { obj.i_call_things }
|
34
35
|
before do
|
35
|
-
allow(CentralBureaucracy).to receive
|
36
|
+
allow(CentralBureaucracy).to receive(:file_report).and_return(file_report)
|
36
37
|
end
|
37
38
|
it "calls CentralBureaucracy.file_report" do
|
38
39
|
subject
|
@@ -46,7 +47,7 @@ Feature: Creates awesome specs
|
|
46
47
|
"""ruby
|
47
48
|
class Lolcat
|
48
49
|
def i_call_instance_methods
|
49
|
-
meth
|
50
|
+
meth.is_bad_for_you
|
50
51
|
end
|
51
52
|
end
|
52
53
|
"""
|
@@ -56,13 +57,17 @@ Feature: Creates awesome specs
|
|
56
57
|
"""ruby
|
57
58
|
describe "#i_call_instance_methods" do
|
58
59
|
let(:obj) { described_class.new }
|
60
|
+
let(:meth) { double(:meth) }
|
61
|
+
let(:is_bad_for_you) { double(:is_bad_for_you) }
|
59
62
|
subject { obj.i_call_instance_methods }
|
60
63
|
before do
|
61
|
-
allow(obj).to receive
|
64
|
+
allow(obj).to receive(:meth).and_return(meth)
|
65
|
+
allow(meth).to receive(:is_bad_for_you).and_return(is_bad_for_you)
|
62
66
|
end
|
63
|
-
it "calls
|
67
|
+
it "calls meth.is_bad_for_you" do
|
64
68
|
subject
|
65
69
|
expect(obj).to have_received :meth
|
70
|
+
expect(meth).to have_received :is_bad_for_you
|
66
71
|
end
|
67
72
|
end
|
68
73
|
"""
|
@@ -1,21 +1,4 @@
|
|
1
1
|
require 'ruby_parser'
|
2
|
+
require 'require_all'
|
2
3
|
|
3
|
-
|
4
|
-
require "code_driven_development/code_driven_development"
|
5
|
-
require "code_driven_development/indented_output"
|
6
|
-
|
7
|
-
require "code_driven_development/test_component/test"
|
8
|
-
require "code_driven_development/test_component/one_line_test"
|
9
|
-
require "code_driven_development/test_component/context"
|
10
|
-
require "code_driven_development/test_component/blank_slate"
|
11
|
-
require "code_driven_development/test_component/let"
|
12
|
-
|
13
|
-
require "code_driven_development/rule/abstract_rule"
|
14
|
-
require "code_driven_development/rule/set"
|
15
|
-
require "code_driven_development/rule/constant_method_call"
|
16
|
-
require "code_driven_development/rule/instance_method_call"
|
17
|
-
require "code_driven_development/rule/default"
|
18
|
-
require "code_driven_development/rule/boolean_or"
|
19
|
-
require "code_driven_development/rule/class"
|
20
|
-
require "code_driven_development/rule/validation"
|
21
|
-
require "code_driven_development/rule/instance_method"
|
4
|
+
require_rel "code_driven_development"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CodeDrivenDevelopment
|
2
|
+
module Rule
|
3
|
+
class MethodCall < AbstractRule
|
4
|
+
def capable?
|
5
|
+
code.sexp_type == :call &&
|
6
|
+
stubber.method_name != :validate
|
7
|
+
end
|
8
|
+
|
9
|
+
def test
|
10
|
+
test_context.doubles.concat(stubber.doubles.map { |sym| TestComponent::Double.new(sym) })
|
11
|
+
test_context.befores.concat(stubber.befores)
|
12
|
+
test_context << TestComponent::Test.new("calls #{stubber.human_name}", ["subject"] + stubber.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def stubber
|
18
|
+
@stubber ||= Stubber::Stubber.new(code)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CodeDrivenDevelopment
|
2
|
+
module Stubber
|
3
|
+
class AbstractStubber
|
4
|
+
def initialize(sexp)
|
5
|
+
@sexp = sexp
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_name
|
9
|
+
sexp[2]
|
10
|
+
end
|
11
|
+
|
12
|
+
def befores
|
13
|
+
[
|
14
|
+
"allow(#{receiver_value}).to receive(:#{method_name}).and_return(#{method_name})"
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def doubles
|
19
|
+
[
|
20
|
+
method_name.to_sym
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def body
|
25
|
+
[
|
26
|
+
"expect(#{receiver_value}).to have_received :#{method_name}"
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :sexp
|
33
|
+
|
34
|
+
def receiver
|
35
|
+
sexp[1]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module CodeDrivenDevelopment
|
2
|
+
module Stubber
|
3
|
+
class NestedCallStubber < AbstractStubber
|
4
|
+
def receiver_value
|
5
|
+
receiver[2]
|
6
|
+
end
|
7
|
+
|
8
|
+
def human_name
|
9
|
+
"#{substubber.human_name}.#{method_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def befores
|
13
|
+
substubber.befores << "allow(#{substubber.method_name}).to receive(:#{method_name}).and_return(#{method_name})"
|
14
|
+
end
|
15
|
+
|
16
|
+
def body
|
17
|
+
substubber.body << "expect(#{substubber.method_name}).to have_received :#{method_name}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def doubles
|
21
|
+
substubber.doubles << method_name.to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def substubber
|
27
|
+
@substubber ||= Stubber.new(receiver)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CodeDrivenDevelopment
|
2
|
+
module Stubber
|
3
|
+
class Stubber
|
4
|
+
def self.new(sexp)
|
5
|
+
raise "That's not a call!" unless sexp.sexp_type == :call
|
6
|
+
|
7
|
+
receiver = sexp[1] && sexp[1].sexp_type
|
8
|
+
|
9
|
+
case receiver
|
10
|
+
when nil
|
11
|
+
InstanceMethodStubber.new(sexp)
|
12
|
+
when :const
|
13
|
+
ConstStubber.new(sexp)
|
14
|
+
when :call
|
15
|
+
NestedCallStubber.new(sexp)
|
16
|
+
else
|
17
|
+
raise "Can't stub #{receiver.inspect} :("
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,10 +2,10 @@ module CodeDrivenDevelopment
|
|
2
2
|
module TestComponent
|
3
3
|
class Context
|
4
4
|
def initialize(description = nil, befores = [], tests = [], lets = [], subject = nil)
|
5
|
-
@description, @befores, @tests, @lets, @subject = description, befores, tests, lets, subject
|
5
|
+
@description, @befores, @tests, @lets, @subject, @doubles = description, befores, tests, lets, subject, []
|
6
6
|
end
|
7
7
|
|
8
|
-
attr_reader :tests, :befores, :lets
|
8
|
+
attr_reader :tests, :befores, :lets, :doubles
|
9
9
|
attr_accessor :description, :subject
|
10
10
|
|
11
11
|
def << child
|
@@ -18,6 +18,9 @@ module CodeDrivenDevelopment
|
|
18
18
|
lets.each do |let|
|
19
19
|
let.indented_output(io)
|
20
20
|
end
|
21
|
+
doubles.each do |double|
|
22
|
+
double.indented_output(io)
|
23
|
+
end
|
21
24
|
if subject
|
22
25
|
io << "subject { #{subject} }"
|
23
26
|
end
|
data/samples/president.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CodeDrivenDevelopment::Stubber::Stubber do
|
4
|
+
let(:sexp) { RubyParser.new.parse(code) }
|
5
|
+
let(:stubber) { CodeDrivenDevelopment::Stubber::Stubber.new(sexp) }
|
6
|
+
|
7
|
+
context "invoking a constant's method" do
|
8
|
+
let(:code) { "Constant.zulu.force" }
|
9
|
+
|
10
|
+
it "stubs like a boss" do
|
11
|
+
expect(stubber.befores).to match_array [
|
12
|
+
"allow(Constant).to receive(:zulu).and_return(zulu)",
|
13
|
+
"allow(zulu).to receive(:force).and_return(force)",
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has a legit human name" do
|
18
|
+
expect(stubber.human_name).to eq "Constant.zulu.force"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can create a test body" do
|
22
|
+
expect(stubber.body).to match_array [
|
23
|
+
"expect(Constant).to have_received :zulu",
|
24
|
+
"expect(zulu).to have_received :force",
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has some doubles" do
|
29
|
+
expect(stubber.doubles).to match_array [:zulu, :force]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "invoking an instance method of self" do
|
34
|
+
let(:code) { "zulu" }
|
35
|
+
|
36
|
+
it "stubs like a boss" do
|
37
|
+
expect(stubber.befores).to eq ["allow(obj).to receive(:zulu).and_return(zulu)"]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a legit human name" do
|
41
|
+
expect(stubber.human_name).to eq "zulu"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can create a test body" do
|
45
|
+
expect(stubber.body).to eq [
|
46
|
+
"expect(obj).to have_received :zulu"
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has some doubles" do
|
51
|
+
expect(stubber.doubles).to match_array [:zulu]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "a double method call" do
|
56
|
+
let(:code) { "alpha.beta" }
|
57
|
+
|
58
|
+
it "stubs like a boss" do
|
59
|
+
expect(stubber.befores).to match_array [
|
60
|
+
"allow(obj).to receive(:alpha).and_return(alpha)",
|
61
|
+
"allow(alpha).to receive(:beta).and_return(beta)",
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has a legit human name" do
|
66
|
+
expect(stubber.human_name).to eq "alpha.beta"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "can create a test body" do
|
70
|
+
expect(stubber.body).to match_array [
|
71
|
+
"expect(obj).to have_received :alpha",
|
72
|
+
"expect(alpha).to have_received :beta",
|
73
|
+
]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "has some doubles" do
|
77
|
+
expect(stubber.doubles).to match_array [:alpha, :beta]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "infinitely nested method calls on self" do
|
82
|
+
let(:code) { "alpha.beta.gamma.delta" }
|
83
|
+
|
84
|
+
it "stubs like a boss" do
|
85
|
+
expect(stubber.befores).to match_array [
|
86
|
+
"allow(obj).to receive(:alpha).and_return(alpha)",
|
87
|
+
"allow(alpha).to receive(:beta).and_return(beta)",
|
88
|
+
"allow(beta).to receive(:gamma).and_return(gamma)",
|
89
|
+
"allow(gamma).to receive(:delta).and_return(delta)",
|
90
|
+
]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "has a legit human name" do
|
94
|
+
expect(stubber.human_name).to eq "alpha.beta.gamma.delta"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can create a test body" do
|
98
|
+
expect(stubber.body).to match_array [
|
99
|
+
"expect(obj).to have_received :alpha",
|
100
|
+
"expect(alpha).to have_received :beta",
|
101
|
+
"expect(beta).to have_received :gamma",
|
102
|
+
"expect(gamma).to have_received :delta",
|
103
|
+
]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "has some doubles" do
|
107
|
+
expect(stubber.doubles).to match_array [:alpha, :beta, :gamma, :delta]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_driven_development
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Finnie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_parser
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: require_all
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coderay
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,21 +160,26 @@ files:
|
|
132
160
|
- lib/code_driven_development/rule/abstract_rule.rb
|
133
161
|
- lib/code_driven_development/rule/boolean_or.rb
|
134
162
|
- lib/code_driven_development/rule/class.rb
|
135
|
-
- lib/code_driven_development/rule/constant_method_call.rb
|
136
163
|
- lib/code_driven_development/rule/default.rb
|
137
164
|
- lib/code_driven_development/rule/instance_method.rb
|
138
|
-
- lib/code_driven_development/rule/
|
165
|
+
- lib/code_driven_development/rule/method_call.rb
|
139
166
|
- lib/code_driven_development/rule/set.rb
|
140
167
|
- lib/code_driven_development/rule/validation.rb
|
168
|
+
- lib/code_driven_development/stubber/abstract_stubber.rb
|
169
|
+
- lib/code_driven_development/stubber/const_stubber.rb
|
170
|
+
- lib/code_driven_development/stubber/instance_method_stubber.rb
|
171
|
+
- lib/code_driven_development/stubber/nested_call_stubber.rb
|
172
|
+
- lib/code_driven_development/stubber/stubber.rb
|
141
173
|
- lib/code_driven_development/test_component/blank_slate.rb
|
142
174
|
- lib/code_driven_development/test_component/context.rb
|
175
|
+
- lib/code_driven_development/test_component/double.rb
|
143
176
|
- lib/code_driven_development/test_component/let.rb
|
144
177
|
- lib/code_driven_development/test_component/one_line_test.rb
|
145
178
|
- lib/code_driven_development/test_component/test.rb
|
146
179
|
- lib/code_driven_development/version.rb
|
147
180
|
- samples/president.rb
|
148
|
-
- spec/samples/lone_sample.yaml
|
149
181
|
- spec/spec_helper.rb
|
182
|
+
- spec/stubber_spec.rb
|
150
183
|
homepage: https://github.com/danfinnie/code-driven-development
|
151
184
|
licenses:
|
152
185
|
- MIT
|
@@ -175,5 +208,5 @@ summary: Ever see a test and think, "wow, this test cares a lot about the exact
|
|
175
208
|
test_files:
|
176
209
|
- features/my_feature.feature
|
177
210
|
- features/support/aruba.rb
|
178
|
-
- spec/samples/lone_sample.yaml
|
179
211
|
- spec/spec_helper.rb
|
212
|
+
- spec/stubber_spec.rb
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module CodeDrivenDevelopment
|
2
|
-
module Rule
|
3
|
-
class ConstantMethodCall < AbstractRule
|
4
|
-
def capable?
|
5
|
-
code.sexp_type == :call &&
|
6
|
-
method_name != :validate &&
|
7
|
-
receiver_type == :const
|
8
|
-
end
|
9
|
-
|
10
|
-
def test
|
11
|
-
test_context.befores << "allow(#{receiver_value}).to receive :#{method_name}"
|
12
|
-
body = [
|
13
|
-
"subject",
|
14
|
-
"expect(#{receiver_value}).to have_received :#{method_name}"
|
15
|
-
]
|
16
|
-
test_context << TestComponent::Test.new("calls #{receiver_value}.#{method_name}", body)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def receiver_value
|
22
|
-
receiver.value
|
23
|
-
end
|
24
|
-
|
25
|
-
def receiver_type
|
26
|
-
receiver && receiver.sexp_type
|
27
|
-
end
|
28
|
-
|
29
|
-
def receiver
|
30
|
-
code[1]
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_name
|
34
|
-
code[2]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module CodeDrivenDevelopment
|
2
|
-
module Rule
|
3
|
-
class InstanceMethodCall < AbstractRule
|
4
|
-
def capable?
|
5
|
-
code.sexp_type == :call &&
|
6
|
-
method_name != :validate &&
|
7
|
-
receiver_type.nil?
|
8
|
-
end
|
9
|
-
|
10
|
-
def test
|
11
|
-
test_context.befores << "allow(#{receiver_value}).to receive :#{method_name}"
|
12
|
-
body = [
|
13
|
-
"subject",
|
14
|
-
"expect(#{receiver_value}).to have_received :#{method_name}"
|
15
|
-
]
|
16
|
-
test_context << TestComponent::Test.new("calls ##{method_name}", body)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def receiver_value
|
22
|
-
"obj"
|
23
|
-
end
|
24
|
-
|
25
|
-
def receiver_type
|
26
|
-
receiver && receiver.sexp_type
|
27
|
-
end
|
28
|
-
|
29
|
-
def receiver
|
30
|
-
code[1]
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_name
|
34
|
-
code[2]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
-
|
2
|
-
title: creates shoulda_matchers
|
3
|
-
input: |
|
4
|
-
class Lolcat < ActiveRecord::Base
|
5
|
-
validate :cuteness, presence: true
|
6
|
-
end
|
7
|
-
output: |
|
8
|
-
describe Lolcat do
|
9
|
-
it { should validate_presence_of :cuteness }
|
10
|
-
end
|
11
|
-
-
|
12
|
-
title: instance methods that call constants
|
13
|
-
input: |
|
14
|
-
class Lolcat
|
15
|
-
def i_call_things
|
16
|
-
CentralBureaucracy.file_report
|
17
|
-
end
|
18
|
-
end
|
19
|
-
output: |
|
20
|
-
describe Lolcat do
|
21
|
-
|
22
|
-
describe "#i_call_things" do
|
23
|
-
let(:obj) { described_class.new }
|
24
|
-
before do
|
25
|
-
allow(CentralBureaucracy).to receive :file_report
|
26
|
-
obj.i_call_things
|
27
|
-
end
|
28
|
-
it "calls CentralBureaucracy.file_report" do
|
29
|
-
expect(CentralBureaucracy).to have_received :file_report
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
-
|
34
|
-
title: instance methods that call instance methods
|
35
|
-
input: |
|
36
|
-
class Lolcat
|
37
|
-
def i_call_instance_methods
|
38
|
-
meth
|
39
|
-
end
|
40
|
-
end
|
41
|
-
output: |
|
42
|
-
describe Lolcat do
|
43
|
-
|
44
|
-
describe "#i_call_instance_methods" do
|
45
|
-
let(:obj) { described_class.new }
|
46
|
-
before do
|
47
|
-
allow(obj).to receive :meth
|
48
|
-
obj.i_call_instance_methods
|
49
|
-
end
|
50
|
-
it "calls #meth" do
|
51
|
-
expect(obj).to have_received :meth
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|