/
questions_spec.rb
61 lines (53 loc) · 1.32 KB
/
questions_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
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
module Auto
describe Auto::Question do
def run
@r.run do
q :q1 => "q1", :q2 => "q2"
end
end
before(:each) do
@r = Runner.new
end
it 'should store questions' do
run
@r.run do
q.should == {
:q1 => "q1" ,
:q2 => "q2"
}
end
end
it 'should trigger a "before question" callback' do
questions = {}
@r.before_question do |key, value|
questions[key] = value
end
run
questions.should == { :q1 => "q1", :q2 => "q2" }
end
it 'should trigger an "after question" callback' do
questions = {}
@r.after_question do |key, value|
questions[key] = value
end
run
questions.should == { :q1 => "q1", :q2 => "q2" }
end
it 'should not trigger "after question" if a "before question" callback returns false' do
@r.before_question { |key, value| false }
@r.after_question do |key, value|
true.should == false # fail test
end
run
end
it 'should yield to a block if specified' do
@r.run do
q :q1 => "q1", :q2 => "q2" do
q[:q1].should == "q1"
q[:q2].should == "q2"
end
end
end
end
end