/
annotate_spec.rb
161 lines (135 loc) · 5.5 KB
/
annotate_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
require 'spec_helper'
describe Guard::Annotate do
subject { Guard::Annotate.new }
context "#initialize options" do
describe "notify" do
it "should be true by default" do
subject.should be_notify
end
it "should allow notifications to be turned off" do
subject = Guard::Annotate.new( [], :notify => false )
subject.options[:notify].should be_false
end
end
describe "position" do
it "should use 'before' position by default" do
subject.options[:position].should == 'before'
end
it "should allow user to customize position (before)" do
subject = Guard::Annotate.new( [], :position => 'before' )
subject.options[:position].should == 'before'
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
subject.start
end
it "should allow user to customize position (after)" do
subject = Guard::Annotate.new( [], :position => 'after' )
subject.options[:position].should == 'after'
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p after")
subject.start
end
end
describe "routes" do
it "should not run routes by default" do
subject.options[:routes].should be_false
end
it "should allow the users to run routes if desired" do
subject = Guard::Annotate.new( [], :routes => true)
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
subject.should_receive(:system).with("bundle exec annotate -r -p before")
subject.start
end
it "should allow the user to customize routes annotation position (before)" do
subject = Guard::Annotate.new( [], :routes => true, :position => 'before')
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
subject.should_receive(:system).with("bundle exec annotate -r -p before")
subject.start
end
it "should allow the user to customize routes annotation position (after)" do
subject = Guard::Annotate.new( [], :routes => true, :position => 'after')
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p after")
subject.should_receive(:system).with("bundle exec annotate -r -p after")
subject.start
end
end
describe "tests & fixtures" do
it "should not run tests annotations by default" do
subject.options[:tests].should be_false
end
it "should allow user to run tests and fixtures annotations if desired" do
subject = Guard::Annotate.new( [], :tests => true )
subject.should_receive(:system).with("bundle exec annotate -p before")
subject.start
end
end
describe "indexes" do
it "should not add indexes to annotations by default" do
subject.options[:show_indexes].should be_false
end
it "should allow user to add indexes to annotations if desired" do
subject = Guard::Annotate.new( [], :show_indexes => true )
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --show-indexes")
subject.start
end
end
describe "run_at_start" do
it "should run at start by default" do
subject.options[:run_at_start].should be_true
end
it "should allow user to opt out of running at start" do
subject = Guard::Annotate.new( [], :run_at_start => false)
subject.options[:run_at_start].should be_false
end
end
end
context "start" do
it "should run annotate command" do
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
subject.start
end
it "should return false if annotate command fails" do
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before").and_return(false)
subject.start.should be_false
end
it 'should not run annotate command if disabled :run_at_start' do
subject.should_not_receive(:system)
subject.options[:run_at_start] = false
subject.start
end
end
context "stop" do
it "should be a noop (return true)" do
subject.stop.should be_true
end
end
context "reload" do
it "should run annotate command" do
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
subject.reload
end
it "should return false if annotate command fails" do
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before").and_return(false)
subject.reload.should be_false
end
it 'should not run annotate command if disabled :run_at_start' do
subject.should_not_receive(:system)
subject.options[:run_at_start] = false
subject.reload
end
end
context "run_all" do
it "should be a noop (return true)" do
subject.run_all.should be_true
end
end
# For Guard 1.1. #run_on_change is deprecated
context "run_on_changes" do
it "should run annotate command" do
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
subject.run_on_changes
end
it "should return false if annotate command fails" do
subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before").and_return(false)
subject.run_on_changes.should be_false
end
end
end