GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of wycats/merb-core
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/auser/merb-core.git
raycmorgan (author)
Sat Mar 15 21:23:26 -0700 2008
ezmobius (committer)
Wed Mar 19 12:20:49 -0700 2008
commit  130ee1ee30e08e23cd4563bce954ecacff88a5b3
tree    3040cdac5906c6a4c6c493a49d6e8a59bc6201ba
parent  ce659ee9d210df80d177d686c836a20d5585c00b
merb-core / spec / public / test / view_helper_spec.rb
100644 96 lines (78 sloc) 2.797 kb
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
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
 
describe Merb::Test::ViewHelper do
  before(:each) do
    @output = Merb::Test::ViewHelper::DocumentOutput.new(test_response)
  end
  
  describe "#tag" do
    it "should return the inner content of the first tag found by the css query" do
      tag(:li).should == "item 1"
    end
  end
  
  describe "#tags" do
    it "should return an array of tag contents for all tags found by the css query" do
      tags(:li).should include("item 1", "item 2", "item 3")
    end
  end
  
  describe "#element" do
    it "should return a raw Hpricot::Elem object for the first result found by the query" do
      Hpricot::Elem.should === element(:body)
    end
  end
  
  describe "#elements" do
    it "should return an array of Hpricot::Elem objects for the results found by the query" do
      elements("li, ul").each{|ele| Hpricot::Elem.should === ele}
    end
  end
  
  describe "#have_tag" do
    it "should work without options hash" do
      have_tag(:html)
    end
    
    it "should work with options hash" do
      have_tag(:html, {})
    end
  end
  
  describe "#get_elements" do
    it "should return an array of Hpricot::Elem objects for the results found by the query containing the filter string" do
      get_elements(:li, "item").size.should == 3
      get_elements(:li, "item 2").size.should == 1
    end
    
    it "should return an array of Hpricot::Elem objects for the results found by the query matching the filter regexp" do
      get_elements(:li, /^item \d$/).size.should == 3
      get_elements(:li, /^item (1|2)$/).size.should == 2
    end
  end
  
  it "should raise an error if the ouput is not specified and cannot be found" do
    @output, @response_output, @controller = nil
    
    lambda { tag("div") }.should raise_error("The response output was not in it's usual places, please provide the output")
  end
  
  it "should use @output if no output parameter is supplied" do
    @output.should_receive(:content_for)
    
    tag(:div)
  end
  
  it "should use @output_response if no output parameter is supplied and @output does not contain output" do
    @output = nil
    @response_output = test_response
    
    tag(:div)
  end
  
  it "should use @controller.body if no output parameter is supplied and both @output and @response_output do not contain output" do
    @output, @response_output = nil
    @controller = mock(:controller)
    @controller.should_receive(:nil?).and_return false
    @controller.should_receive(:body).any_number_of_times.and_return test_response
    
    tag(:div)
  end
  
  def test_response
    <<-EOR
<html>
<body>
<div>Hello, World!</div>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul
</body>
</html>
EOR
  end
end