Changeset 734
- Timestamp:
- 10/09/07 18:09:01 (1 year ago)
- Files:
-
- plugins/merb_helpers/specs/merb_helpers_spec.rb (modified) (5 diffs)
- plugins/merb_helpers/specs/spec_helper.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/merb_helpers/specs/merb_helpers_spec.rb
r732 r734 83 83 describe "text_field (basic)" do 84 84 it "should return a basic text field based on the values passed in" do 85 text_field(:name => "foo", :value => "bar").should == "<input type=\"text\" name=\"foo\" value=\"bar\"/>"85 text_field(:name => "foo", :value => "bar").should match_tag( :input, :type => "text", :name => "foo", :value => "bar") 86 86 end 87 87 end … … 104 104 105 105 describe "checkbox_field (basic)" do 106 include TagMatchers107 108 106 it "should return a basic checkbox based on the values passed in" do 109 107 checkbox_field(:name => "foo", :checked => "checked").should match_tag(:input, :class => "checkbox", :name => "foo", :checked => "checked") … … 133 131 134 132 describe "hidden_field (basic)" do 135 include TagMatchers136 133 137 134 it "should return a basic checkbox based on the values passed in" do … … 158 155 159 156 describe "radio button (basic)" do 160 include TagMatchers161 157 it "should should return a basic radio button based on the values passed in" do 162 158 radio_field(:name => "foo", :value => "bar").should match_tag(:input, :type => "radio", :name => "foo", :value => "bar") … … 178 174 179 175 describe "text area (basic)" do 180 include TagMatchers176 # include TagMatchers 181 177 it "should should return a basic text area based on the values passed in" do 182 178 text_area_field("foo", :name => "foo").should match_tag(:textarea, :name => "foo") plugins/merb_helpers/specs/spec_helper.rb
r731 r734 3 3 require 'rubygems' 4 4 require 'merb' 5 6 module TagMatchers 7 class MatchTag 8 def initialize(name, attrs) 9 @name, @attrs = name, attrs 10 end 11 12 def matches?(target) 13 @errors = [] 14 unless target.include?("<#{@name}") 15 @errors << "Expected a <#{@name}>, but was #{target}" 16 end 17 @attrs.each do |attr, val| 18 unless target.include?("#{attr}=\"#{val}\"") 19 @errors << "Expected #{attr}=\"#{val}\", but was #{target}" 20 end 21 end 22 @errors.size == 0 23 end 24 25 def failure_message 26 @errors[0] 27 end 28 end 29 30 class NotMatchTag 31 def initialize(attrs) 32 @attrs = attrs 33 end 34 35 def matches?(target) 36 @errors = [] 37 @attrs.each do |attr, val| 38 if target.include?("#{attr}=\"#{val}\"") 39 @errors << "Should not include #{attr}=\"#{val}\", but was #{target}" 40 end 41 end 42 @errors.size == 0 43 end 44 45 def failure_message 46 @errors[0] 47 end 48 end 49 50 def match_tag(name, attrs) 51 MatchTag.new(name, attrs) 52 end 53 def not_match_tag(attrs) 54 NotMatchTag.new(attrs) 55 end 56 end 5 require 'merb/test/rspec' 57 6 58 7 class FakeModel … … 126 75 end 127 76 77 78 79 128 80 describe "FakeBufferConsumer", :shared => true do 129 include TagMatchers130 81 131 82 before :each do
