require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Suhyo::ViewMatchers do
include Suhyo::ViewMatchers
describe '#have_link' do
it 'matches with no options' do
'Foo'.should have_link
end
it 'matches the text' do
'Foo'.should have_link(:text => 'Foo')
end
it 'matches the URL' do
'Foo'.should have_link(:url => 'http://example.com')
end
it 'matches the ancestors' do
'
'.should have_link(:ancestors => 'div#main')
end
it 'does not match when there is no link' do
'
Foo
'.should_not have_link
end
it 'does not match when the text is wrong' do
'Foo'.should_not have_link(:text => 'Bar')
end
it 'does not match when the URL is wrong' do
'Foo'.should_not have_link(:url => 'http://google.com')
end
it 'does not match when the ancestors are wrong' do
'Foo'.should_not have_link(:ancestors => 'div#main')
end
end
describe '#have_restful_form' do
def restful_form(method)
case method
when 'get'
browser_method = 'get'
hidden_field = nil
when 'post'
browser_method = 'post'
hidden_field = nil
when 'put'
browser_method = 'post'
hidden_field = ''
when 'delete'
browser_method = 'post'
hidden_field = ''
end
%Q{}
end
%w(get post put delete).each do |expected_method|
it "matches a #{expected_method.upcase} form" do
restful_form(expected_method).should have_restful_form(expected_method)
end
(%w(get post put delete) - [expected_method]).each do |actual_method|
it "does not match #{expected_method.upcase} when the method is #{actual_method.upcase}" do
restful_form(actual_method).should_not have_restful_form(expected_method)
end
end
end
it 'matches the ancestors' do
('
' + restful_form('get') + '
').should have_restful_form('get', :ancestors => 'div#main')
end
it 'does not match if the ancestors are wrong' do
restful_form('get').should_not have_restful_form('get', :ancestors => 'div#main')
end
it 'matches arbitrary attributes' do
''.should have_restful_form('get', :action => 'http://example.com')
''.should_not have_restful_form('get', :action => 'http://google.com')
end
it 'raises ArgumentError if method is not get, post, put, or delete' do
lambda { restful_form('get').should have_restful_form('foo') }.should raise_error(ArgumentError)
lambda { restful_form('get').should have_restful_form(42) }.should raise_error(ArgumentError)
end
it 'raises ArgumentError if options is not a hash' do
lambda { restful_form('get').should have_restful_form('get', 42) }.should raise_error(ArgumentError)
lambda { restful_form('get').should have_restful_form('get', 'foo') }.should raise_error(ArgumentError)
end
end
end