require 'spec'
require 'rubygems'
gem 'webrat', '>=0.2.1'
require 'webrat/core'
require 'webrat/mechanize'

def method_missing(name, *args, &block)
if webrat_session.respond_to?(name)
webrat_session.send(name, *args, &block)
else
super
end
end

def webrat_session
@webrat_session ||= Webrat::MechanizeSession.new
end

After do
visits "http://mysite.local/admin/logout"
end

Given "I have logged in to admin" do
visits "http://mysite.local/admin"
fills_in 'login', :with => '*****'
fills_in 'password', :with => '*****'
clicks_button 'Login to CMS'
end

When /I go to \/(.+)/ do |op|
visits "http://mysite.local/#{op}"
end

Then /the page should load successfully/
response_code.should == 200
end

Then /the (.+?) form should display/ do |form_name|
parsed = Hpricot(response_body)
parsed.search("form[@action=/admin/cms.#{form_name}_edit.php]").size.should == 1
end

Then /the (.+?) list should display/ do |form_name|
parsed = Hpricot(response_body)
parsed.search("*[@class=listHeader]").should_not be_empty
parsed.search("a[@href:contains('cms.#{form_name}_edit.php')]").should_not be_empty
end