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
Foo
Bar
'.should contain_in_order('Foo', :before => 'Bar') end it 'does not match when the content is in the reverse order' do 'Bar
Foo
'.should_not contain_in_order('Foo', :before => 'Bar') end it 'does not match when the first content is missing' do '...
Bar
'.should_not contain_in_order('Foo', :before => 'Bar') end it 'does not match when the second content is missing' do 'Foo
...
'.should_not contain_in_order('Foo', :before => 'Bar') end end context 'matching after' do it 'matches when the content is in the right order' do 'Foo
Bar
'.should contain_in_order('Bar', :after => 'Foo') end it 'does not match when the content is in the reverse order' do 'Bar
Foo
'.should_not contain_in_order('Bar', :after => 'Foo') end it 'does not match when the first content is missing' do 'Foo
...
'.should_not contain_in_order('Bar', :after => 'Foo') end it 'does not match when the second content is missing' do '...
Bar
'.should_not contain_in_order('Bar', :after => 'Foo') end 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 ('