forked from adamsalter/sitemap_generator
/
application_spec.rb
69 lines (58 loc) · 1.51 KB
/
application_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 'spec_helper'
describe SitemapGenerator::Application do
before :all do
SitemapGenerator::Utilities.with_warnings(nil) do
Object.const_set(:Rails, Object.new)
end
end
after :all do
SitemapGenerator::Utilities.with_warnings(nil) do
Object.const_set(:Rails, nil)
end
end
before :each do
@app = SitemapGenerator::Application.new
end
describe "rails3?" do
tests = {
:nil => false,
'2.3.11' => false,
'3.0.1' => true,
'3.0.11' => true
}
it "should identify the rails version correctly" do
tests.each do |version, result|
Rails.expects(:version).returns(version)
@app.rails3?.should == result
end
end
end
describe "with Rails" do
before :each do
@root = '/test'
Rails.expects(:root).returns(@root).at_least_once
end
it "should use the Rails.root" do
@app.root.should be_a(Pathname)
@app.root.to_s.should == @root
(@app.root + 'public/').to_s.should == File.join(@root, 'public/')
end
end
describe "with no Rails" do
before :each do
@rails = Rails
Object.send(:remove_const, :Rails)
end
after :each do
Object::Rails = @rails
end
it "should not be Rails" do
@app.rails?.should be_false
end
it "should use the current working directory" do
@app.root.should be_a(Pathname)
@app.root.to_s.should == Dir.getwd
(@app.root + 'public/').to_s.should == File.join(Dir.getwd, 'public/')
end
end
end