/
constructor_spec.rb
76 lines (65 loc) · 2.13 KB
/
constructor_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'spec_helper'
describe AssemblyLine::Constructor do
let(:code_block) do
lambda do
depends_on :drinks
let(:host) { :rochelle }
let(:attendees) { [] }
end
end
let(:constructor) { AssemblyLine::Constructor.new(:gathering, code_block) }
let(:rspec_context) { mock('rspec_context', :let => nil, :depends_on => nil) }
let(:options) { {:depends_on => :location} }
describe "#assemble" do
before do
constructor.stub(:depends_on => nil)
end
it "persists context" do
constructor.assemble(rspec_context, options)
constructor.context.should == rspec_context
end
it "persists context" do
constructor.assemble(rspec_context, options)
constructor.options.should == options
end
it "evaluates the code block" do
rspec_context.should_receive(:let).twice
constructor.assemble(rspec_context, options)
end
it "returns itself" do
constructor.assemble(rspec_context, options).should == constructor
end
end
describe "#invoke" do
context "no arguments provided" do
it "calls the 'gathering' method" do
constructor.should_receive(:invoke_in_setup).with(:gathering)
constructor.invoke
end
end
context "arguments provided" do
it "calls the 'host' method" do
constructor.should_receive(:invoke_in_setup).with(:host)
constructor.invoke :host
end
it "calls the 'host' method followed by the 'attendees' method" do
constructor.should_receive(:invoke_in_setup).with(:host, :attendees)
constructor.invoke :host, :attendees
end
end
end
describe "#depends_on" do
context "declared in the assembly" do
it "attempts to assemble the 'drinks' dependency" do
AssemblyLine.should_receive(:assemble).with(:drinks, rspec_context)
constructor.assemble(rspec_context, {})
end
end
context "passed in from options" do
it "attempts to assemble the 'location' assembly" do
AssemblyLine.should_receive(:assemble).with(:location, rspec_context)
constructor.assemble(rspec_context, options)
end
end
end
end