forked from avdi/gem-love
/
fan_spec.rb
69 lines (56 loc) · 1.87 KB
/
fan_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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'construct'
module GemLove
describe Fan do
include Construct::Helpers
before :each do
@construct = create_construct
@ui = stub("UI")
@ui.stub(:ask).with(/name/).and_return("Tom Servo")
@ui.stub(:ask).with(/email/).and_return("tom@sol.net")
end
after :each do
@construct.destroy!
end
context "initialized with no saved user info" do
it "should prompt for name and email address" do
@ui.should_receive(:ask).with(/name/).
and_return("Tom Servo")
@ui.should_receive(:ask).with(/email/).
and_return("tom@sol.net")
fan = Fan.load_or_init(@ui, :home_dir => @construct)
end
end
context "for a fresh user" do
subject { Fan.load_or_init(@ui, :home_dir => @construct) }
it "should have the entered name" do
subject.name.should == "Tom Servo"
end
it "should have the entered email" do
subject.email_address.should == "tom@sol.net"
end
it "should save the entered name" do
subject # force init
saved_fan = YAML.load_file((@construct + '.gem' + 'love.yml').to_s)
saved_fan.name.should == "Tom Servo"
end
it "should save the entered email" do
subject # force init
saved_fan = YAML.load_file((@construct + '.gem' + 'love.yml').to_s)
saved_fan.email_address.should == "tom@sol.net"
end
end
context "for a saved user" do
before :each do
@construct.file ".gem/love.yml" do |f|
fan = Fan.new("Crow T Robot", "crow@sol.net")
YAML.dump(fan, f)
end
end
it "should not prompt the user on init" do
@ui.should_not_receive(:ask)
Fan.load_or_init(@ui, :home_dir => @construct)
end
end
end
end