Added prelimary support for fully qualified links starting with http:// or https://. Restored missing commits(???)

This commit is contained in:
Luke Melia 2008-05-04 04:15:36 -04:00
parent 2ef317f2cf
commit 73d3b72108
19 changed files with 359 additions and 206 deletions

View File

@ -2,9 +2,11 @@
* Enhancements * Enhancements
* Support file fields using attaches_file (Patch from Kyle Hargraves)
* Support button elements (Patch from Nick Sieger) * Support button elements (Patch from Nick Sieger)
* Support matching select options by regexp (Patch from Kyle Hargraves) * Support matching select options by regexp (Patch from Kyle Hargraves)
* Support relative links, including href="?foo=bar" (Patch from Kyle Hargraves) * Support relative links, including href="?foo=bar" (Patch from Kyle Hargraves)
* Support links to fully qualified URLs starting with http:// or https:// (Luke Melia)
* Bug fixes * Bug fixes
@ -26,7 +28,7 @@
* Added reloads method to reload the page (Patch from Kamal Fariz Mahyuddi) * Added reloads method to reload the page (Patch from Kamal Fariz Mahyuddi)
* Prevent making a request if clicking on local anchor link (Patch from Kamal Fariz Mahyuddi) * Prevent making a request if clicking on local anchor link (Patch from Kamal Fariz Mahyuddi)
* Added clicks_link_within(selector, link_text), allowing restricting link search * Added clicks_link_within(selector, link_text), allowing restricting link search
to within a given css selector (Path from Luke Melia) to within a given css selector (Patch from Luke Melia)
* Allow specifying the input name/label when doing a select (Patch from David Chelimsky) * Allow specifying the input name/label when doing a select (Patch from David Chelimsky)
* Raise a specific exception if the developer tries to manipulate form elements before loading a page (Patch from James Deville) * Raise a specific exception if the developer tries to manipulate form elements before loading a page (Patch from James Deville)
* Add support for alternate POST, PUT and DELETE link clicking (Patch from Kyle Hargraves) * Add support for alternate POST, PUT and DELETE link clicking (Patch from Kyle Hargraves)

View File

@ -1,14 +1,14 @@
= Webrat - Ruby Acceptance Testing for Web applications Webrat
======
http://rubyforge.org/projects/webrat - [Code on GitHub](http://github.com/brynary/webrat)
http://github.com/brynary/webrat - [Tickets on Lighthouse](http://webrat.lighthouseapp.com/)
* mailto:bryan@brynary.com Description
* mailto:seth@mojodna.net -----------
== DESCRIPTION: Webrat (_Ruby Acceptance Testing for Web applications_)
lets you quickly write robust and thorough acceptance tests for a Ruby
Webrat lets you quickly write robust and thorough acceptance tests for a Ruby
web application. By leveraging the DOM, it can run tests similarly to an web application. By leveraging the DOM, it can run tests similarly to an
in-browser testing solution without the associated performance hit (and in-browser testing solution without the associated performance hit (and
browser dependency). The result is tests that are less fragile and more browser dependency). The result is tests that are less fragile and more
@ -19,20 +19,21 @@ Selenium, the primary consideration should be how much JavaScript the
application uses. In-browser testing is currently the only way to test JS, and application uses. In-browser testing is currently the only way to test JS, and
that may make it a requirement for your project. If JavaScript is not central that may make it a requirement for your project. If JavaScript is not central
to your application, Webrat is a simpler, effective solution that will let you to your application, Webrat is a simpler, effective solution that will let you
run your tests much faster and more frequently. (Benchmarks forthcoming.) run your tests much faster and more frequently.
Initial development was sponsored by EastMedia (http://www.eastmedia.com). Initial development was sponsored by [EastMedia](http://www.eastmedia.com).
== SYNOPSIS: Synopsis
--------
def test_sign_up def test_sign_up
visits "/" visits "/"
clicks_link "Sign up" clicks_link "Sign up"
fills_in "Email", :with => "good@example.com" fills_in "Email", :with => "good@example.com"
selects "Free account" selects "Free account"
clicks_button "Register" clicks_button "Register"
... ...
end end
Behind the scenes, this will perform the following work: Behind the scenes, this will perform the following work:
@ -50,37 +51,47 @@ Behind the scenes, this will perform the following work:
Take special note of the things _not_ specified in that test, that might cause Take special note of the things _not_ specified in that test, that might cause
tests to break unnecessarily as your application evolves: tests to break unnecessarily as your application evolves:
* The input field IDs or names (e.g. "user_email" or "user[email]"), which - The input field IDs or names (e.g. "user_email" or "user[email]"), which
could change if you rename a model could change if you rename a model
* The ID of the form element (Webrat can do a good job of guessing, even if - The ID of the form element (Webrat can do a good job of guessing, even if
there are multiple forms on the page.) there are multiple forms on the page.)
* The URLs of links followed - The URLs of links followed
* The URL the form submission should be sent to, which could change if you - The URL the form submission should be sent to, which could change if you
adjust your routes or controllers adjust your routes or controllers
* The HTTP method for the login request - The HTTP method for the login request
A test written with Webrat can handle these changes smoothly. A test written with Webrat can handle these changes to these without any modifications.
== REQUIREMENTS: Install
-------
* Rails >= 1.2.6 To install the latest release:
* Hpricot >= 0.6
* Rails integration tests in Test::Unit _or_
* RSpec stories (using an RSpec version >= revision 2997)
== INSTALL: sudo gem install webrat
In your stories/helper.rb: In your stories/helper.rb:
require "webrat" require "webrat"
You could also unpack the gem into vendor/plugins. You could also unpack the gem into vendor/plugins.
== HISTORY: Requirements
------------
See CHANGELOG in this directory. - Rails >= 1.2.6
- Hpricot >= 0.6
- Rails integration tests in Test::Unit _or_
- RSpec stories (using an RSpec version >= revision 2997)
== LICENSE: Authors
-------
- Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com)
- Original code written by [Seth Fitzsimmons](mailto:seth@mojodna.net)
- Many other contributors. See attributions in History.txt
License
-------
Copyright (c) 2007 Bryan Helmkamp, Seth Fitzsimmons. Copyright (c) 2007 Bryan Helmkamp, Seth Fitzsimmons.
See MIT-LICENSE in this directory. See MIT-LICENSE.txt in this directory.

View File

@ -1,5 +1,7 @@
require 'rubygems' require 'rubygems'
require 'hoe' require 'hoe'
require 'spec'
require 'spec/rake/spectask'
require './lib/webrat.rb' require './lib/webrat.rb'
Hoe.new('webrat', Webrat::VERSION) do |p| Hoe.new('webrat', Webrat::VERSION) do |p|
@ -16,10 +18,48 @@ Hoe.new('webrat', Webrat::VERSION) do |p|
p.extra_deps << ["hpricot", ">= 0.6"] p.extra_deps << ["hpricot", ">= 0.6"]
p.remote_rdoc_dir = '' # Release to root p.remote_rdoc_dir = '' # Release to root
p.test_globs = ['test/**/*_test.rb']
end end
desc "Upload rdoc to brynary.com" desc "Upload rdoc to brynary.com"
task :publish_rdoc => :docs do task :publish_rdoc => :docs do
sh "scp -r doc/ brynary.com:/apps/uploads/webrat" sh "scp -r doc/ brynary.com:/apps/uploads/webrat"
end
Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
end
def remove_task(task_name)
Rake.application.remove_task(task_name)
end
remove_task "test"
remove_task "test_deps"
desc "Run all specs in spec directory"
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
end
desc "Run all specs in spec directory with RCov"
Spec::Rake::SpecTask.new(:rcov) do |t|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
t.rcov = true
t.rcov_opts = lambda do
IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
end
end
require 'spec/rake/verify_rcov'
RCov::VerifyTask.new(:verify_rcov => :rcov) do |t|
t.threshold = 95.5 # Make sure you have rcov 0.7 or higher!
end
remove_task "default"
task :default do
Rake::Task["verify_rcov"].invoke
end end

View File

@ -35,7 +35,7 @@ module ActionController
current_page.save_and_open current_page.save_and_open
end end
[:reloads, :fills_in, :clicks_button, :selects, :chooses, :checks, :unchecks, :clicks_link, :clicks_link_within, :clicks_put_link, :clicks_get_link, :clicks_post_link, :clicks_delete_link].each do |method_name| [:reloads, :fills_in, :clicks_button, :selects, :attaches_file, :chooses, :checks, :unchecks, :clicks_link, :clicks_link_within, :clicks_put_link, :clicks_get_link, :clicks_post_link, :clicks_delete_link].each do |method_name|
define_method(method_name) do |*args| define_method(method_name) do |*args|
current_page.send(method_name, *args) current_page.send(method_name, *args)
end end

View File

@ -97,6 +97,21 @@ module Webrat
end end
end end
def replace_param_value(params, oval, nval)
output = Hash.new
params.each do |key, value|
case value
when Hash
value = replace_param_value(value, oval, nval)
when Array
value = value.map { |o| o == oval ? nval : oval }
when oval
value = nval
end
output[key] = value
end
output
end
end end
class ButtonField < Field class ButtonField < Field
@ -221,6 +236,15 @@ module Webrat
end end
class FileField < Field class FileField < Field
def to_param
if @value.nil?
super
else
replace_param_value(super, @value, ActionController::TestUploadedFile.new(@value))
end
end
end end
class TextField < Field class TextField < Field

View File

@ -10,6 +10,7 @@ module Webrat
method ||= http_method method ||= http_method
return if href =~ /^#/ && method == :get return if href =~ /^#/ && method == :get
update_protocol(href)
Page.new(@page.session, absolute_href, method, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}) Page.new(@page.session, absolute_href, method, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token})
end end
@ -26,9 +27,19 @@ module Webrat
def href def href
@element["href"] @element["href"]
end end
def update_protocol(href)
if href =~ /^https:/
@page.session.https!(true)
elsif href =~ /^http:/
@page.session.https!(false)
end
end
def absolute_href def absolute_href
if href =~ /^\?/ if href =~ %r{^https?://www.example.com(/.*)}
$LAST_MATCH_INFO.captures.first
elsif href =~ /^\?/
"#{@page.url}#{href}" "#{@page.url}#{href}"
elsif href !~ /^\// elsif href !~ /^\//
"#{@page.url}/#{href}" "#{@page.url}/#{href}"

View File

@ -88,6 +88,17 @@ module Webrat
option.choose option.choose
end end
# Verifies that an input file field exists on the current page and sets
# its value to the given +file+, so that the file will be uploaded
# along with the form.
#
# Example:
# attaches_file "Photo", "/path/to/the/photo.jpg"
def attaches_file(id_or_name_or_label, path)
field = find_field(id_or_name_or_label, FileField)
field.set(path)
end
# Saves the currently loaded page out to RAILS_ROOT/tmp/ and opens it in the default # Saves the currently loaded page out to RAILS_ROOT/tmp/ and opens it in the default
# web browser if on OS X. Useful for debugging. # web browser if on OS X. Useful for debugging.
# #

View File

@ -0,0 +1,62 @@
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
describe "attaches_file" do
before do
@session = ActionController::Integration::Session.new
@session.stubs(:assert_response)
@session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock)
@filename = __FILE__
@uploaded_file = mock
ActionController::TestUploadedFile.stubs(:new).returns(@uploaded_file)
end
it "should fail if no file field found" do
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/widgets">
</form>
EOS
lambda { @session.attaches_file("Doc", "/some/path") }.should raise_error
end
it "should submit empty strings for blank file fields" do
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/widgets">
<input type="file" id="widget_file" name="widget[file]" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/widgets", { "widget" => { "file" => "" } })
@session.clicks_button
end
it "should submit the attached file" do
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/widgets">
<label for="widget_file">Document</label>
<input type="file" id="widget_file" name="widget[file]" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/widgets", { "widget" => { "file" => @uploaded_file } })
@session.attaches_file "Document", @filename
@session.clicks_button
end
it "should support collections" do
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/widgets">
<label for="widget_file1">Document</label>
<input type="file" id="widget_file1" name="widget[files][]" />
<label for="widget_file2">Spreadsheet</label>
<input type="file" id="widget_file2" name="widget[files][]" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } })
@session.attaches_file "Document", @filename
@session.attaches_file "Spreadsheet", @filename
@session.clicks_button
end
end

View File

@ -1,37 +1,33 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ChecksTest < Test::Unit::TestCase describe "checks" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_no_checkbox_found it "should fail if no checkbox found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.checks "remember_me" }.should raise_error
@session.checks "remember_me"
end
end end
def test_should_fail_if_input_is_not_a_checkbox it "should fail if input is not a checkbox" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="remember_me" /> <input type="text" name="remember_me" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.checks "remember_me" }.should raise_error
@session.checks "remember_me"
end
end end
def test_should_check_rails_style_checkboxes it "should check rails style checkboxes" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" />
@ -45,7 +41,7 @@ class ChecksTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_the_value_on_being_posted_if_not_specified it "should result in the value on being posted if not specified" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" /> <input type="checkbox" name="remember_me" />
@ -57,7 +53,7 @@ class ChecksTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_a_custom_value_being_posted it "should result in a custom value being posted" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" /> <input type="checkbox" name="remember_me" value="yes" />
@ -70,38 +66,34 @@ class ChecksTest < Test::Unit::TestCase
end end
end end
class UnchecksTest < Test::Unit::TestCase describe "unchecks" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_no_checkbox_found it "should fail if no checkbox found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.unchecks "remember_me" }.should raise_error
@session.unchecks "remember_me"
end
end end
def test_should_fail_if_input_is_not_a_checkbox it "should fail if input is not a checkbox" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="remember_me" /> <input type="text" name="remember_me" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.unchecks "remember_me" }.should raise_error
@session.unchecks "remember_me"
end
end end
def test_should_uncheck_rails_style_checkboxes it "should uncheck rails style checkboxes" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
@ -116,7 +108,7 @@ class UnchecksTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_value_not_being_posted it "should result in value not being posted" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" /> <input type="checkbox" name="remember_me" value="yes" checked="checked" />

View File

@ -1,38 +1,33 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ChoosesTest < Test::Unit::TestCase describe "chooses" do
before do
def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_no_radio_buttons_found it "should fail if no radio buttons found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.chooses "first option" }.should raise_error
@session.chooses "first option"
end
end end
def test_should_fail_if_input_is_not_a_radio_button it "should fail if input is not a radio button" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="first_option" /> <input type="text" name="first_option" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.chooses "first_option" }.should raise_error
@session.chooses "first_option"
end
end end
def test_should_check_rails_style_radio_buttons it "should check rails style radio buttons" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -47,7 +42,7 @@ class ChoosesTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_only_submit_last_chosen_value it "should only submit last chosen value" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -63,7 +58,7 @@ class ChoosesTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_the_value_on_being_posted_if_not_specified it "should result in the value on being posted if not specified" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" /> <input type="radio" name="first_option" />
@ -75,7 +70,7 @@ class ChoosesTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_result_in_the_value_on_being_posted_if_not_specified_and_checked_by_default it "should result in the value on being posted if not specified and checked by default" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/> <input type="radio" name="first_option" checked="checked"/>
@ -85,5 +80,4 @@ class ChoosesTest < Test::Unit::TestCase
@session.expects(:post_via_redirect).with("/login", "first_option" => "on") @session.expects(:post_via_redirect).with("/login", "first_option" => "on")
@session.clicks_button @session.clicks_button
end end
end
end

View File

@ -1,7 +1,7 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ClicksButtonTest < Test::Unit::TestCase describe "clicks_button" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@ -11,29 +11,25 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.stubs(:response).returns(@response) @session.stubs(:response).returns(@response)
end end
def test_should_fail_if_no_buttons it "should fail if no buttons" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"></form> <form method="get" action="/login"></form>
EOS EOS
assert_raises RuntimeError do lambda { @session.clicks_button }.should raise_error
@session.clicks_button
end
end end
def test_should_fail_if_input_is_not_a_submit_button it "should fail if input is not a submit button" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input type="reset" /> <input type="reset" />
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.clicks_button }.should raise_error
@session.clicks_button
end
end end
def test_should_default_to_get_method it "should default to get method" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
@ -43,7 +39,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_assert_valid_response it "should assert valid response" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
@ -53,7 +49,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_default_to_current_url it "should default to current url" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get"> <form method="get">
<input type="submit" /> <input type="submit" />
@ -64,7 +60,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_submit_the_first_form_by_default it "should submit the first form by default" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="submit" /> <input type="submit" />
@ -77,7 +73,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_not_explode_on_file_fields it "should not explode on file fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="file" /> <input type="file" />
@ -87,7 +83,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_submit_the_form_with_the_specified_button it "should submit the form with the specified button" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="submit" /> <input type="submit" />
@ -100,7 +96,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button "Form2" @session.clicks_button "Form2"
end end
def test_should_use_action_from_form it "should use action from form" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input type="submit" /> <input type="submit" />
@ -110,7 +106,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_use_method_from_form it "should use method from form" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" /> <input type="submit" />
@ -120,7 +116,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_button_as_param_if_it_has_a_name it "should send button as param if it has a name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" /> <input type="submit" name="cancel" value="Cancel" />
@ -131,7 +127,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button("Login") @session.clicks_button("Login")
end end
def test_should_not_send_button_as_param_if_it_has_no_name it "should not send button as param if it has no name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" /> <input type="submit" name="cancel" value="Cancel" />
@ -142,7 +138,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button("Login") @session.clicks_button("Login")
end end
def test_should_send_default_password_field_values it "should send default password field values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_password" name="user[password]" value="mypass" type="password" /> <input id="user_password" name="user[password]" value="mypass" type="password" />
@ -153,7 +149,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_hidden_field_values it "should send default hidden field values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" /> <input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
@ -164,7 +160,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_text_field_values it "should send default text field values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="text" /> <input id="user_email" name="user[email]" value="test@example.com" type="text" />
@ -175,7 +171,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_checked_fields it "should send default checked fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" /> <input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" />
@ -186,7 +182,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_radio_options it "should send default radio options" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -200,7 +196,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_correct_data_for_rails_style_unchecked_fields it "should send correct data for rails style unchecked fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" />
@ -212,7 +208,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_correct_data_for_rails_style_checked_fields it "should send correct data for rails style checked fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
@ -224,7 +220,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_collection_fields it "should send default collection fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="options[]" value="burger" checked="checked" /> <input type="checkbox" name="options[]" value="burger" checked="checked" />
@ -246,7 +242,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_not_send_default_unchecked_fields it "should not send default unchecked fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" /> <input id="user_tos" name="user[tos]" value="1" type="checkbox" />
@ -257,7 +253,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_textarea_values it "should send default textarea values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/posts"> <form method="post" action="/posts">
<textarea name="post[body]">Post body here!</textarea> <textarea name="post[body]">Post body here!</textarea>
@ -268,7 +264,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_selected_option_value_from_select it "should send default selected option value from select" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
@ -282,7 +278,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_selected_option_inner_html_from_select_when_no_value_attribute it "should send default selected option inner html from select when no value attribute" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
@ -296,7 +292,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_first_select_option_value_when_no_option_selected it "should send first select option value when no option selected" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
@ -310,7 +306,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_handle_nested_properties it "should handle nested properties" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/> <input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/>
@ -322,7 +318,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_default_empty_text_field_values it "should send default empty text field values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
@ -333,7 +329,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_recognize_button_tags it "should recognize button tags" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
@ -344,7 +340,7 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_recognize_button_tags_by_content it "should recognize button tags by content" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />

View File

@ -1,14 +1,14 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class ClicksLinkTest < Test::Unit::TestCase describe "clicks_link" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_use_get_by_default it "should use get by default" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -16,7 +16,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_click_get_links it "should click get links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -24,7 +24,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_get_link "Link text" @session.clicks_get_link "Link text"
end end
def test_should_click_delete_links it "should click delete links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -32,7 +32,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_delete_link "Link text" @session.clicks_delete_link "Link text"
end end
def test_should_click_post_links it "should click post links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -40,7 +40,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_post_link "Link text" @session.clicks_post_link "Link text"
end end
def test_should_click_put_links it "should click put links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -48,7 +48,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_put_link "Link text" @session.clicks_put_link "Link text"
end end
def test_should_click_rails_javascript_links_with_authenticity_tokens it "should click rails javascript links with authenticity tokens" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -67,7 +67,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Posts" @session.clicks_link "Posts"
end end
def test_should_click_rails_javascript_delete_links it "should click rails javascript delete links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts/1" onclick="var f = document.createElement('form'); <a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -86,7 +86,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Delete" @session.clicks_link "Delete"
end end
def test_should_click_rails_javascript_post_links it "should click rails javascript post links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -100,7 +100,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Posts" @session.clicks_link "Posts"
end end
def test_should_click_rails_javascript_put_links it "should click rails javascript put links" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
@ -119,7 +119,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Put" @session.clicks_link "Put"
end end
def test_should_assert_valid_response it "should assert valid response" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -127,7 +127,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_not_be_case_sensitive it "should not be case sensitive" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@ -135,7 +135,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "LINK TEXT" @session.clicks_link "LINK TEXT"
end end
def test_should_match_link_substrings it "should match link substrings" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page">This is some cool link text, isn't it?</a> <a href="/page">This is some cool link text, isn't it?</a>
EOS EOS
@ -143,7 +143,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_work_with_elements_in_the_link it "should work with elements in the link" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page"><span>Link text</span></a> <a href="/page"><span>Link text</span></a>
EOS EOS
@ -151,7 +151,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_match_the_first_matching_link it "should match the first matching link" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page1">Link text</a> <a href="/page1">Link text</a>
<a href="/page2">Link text</a> <a href="/page2">Link text</a>
@ -160,7 +160,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
def test_should_choose_the_shortest_link_text_match it "should choose the shortest link text match" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page1">Linkerama</a> <a href="/page1">Linkerama</a>
<a href="/page2">Link</a> <a href="/page2">Link</a>
@ -170,7 +170,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link" @session.clicks_link "Link"
end end
def test_should_click_link_within_a_selector it "should click link within a selector" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="/page1">Link</a> <a href="/page1">Link</a>
<div id="container"> <div id="container">
@ -182,7 +182,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link_within "#container", "Link" @session.clicks_link_within "#container", "Link"
end end
def test_should_not_make_request_when_link_is_local_anchor it "should not make request when link is local anchor" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="#section-1">Jump to Section 1</a> <a href="#section-1">Jump to Section 1</a>
EOS EOS
@ -191,7 +191,7 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Jump to Section 1" @session.clicks_link "Jump to Section 1"
end end
def test_should_follow_relative_links it "should follow relative links" do
@session.current_page.stubs(:url).returns("/page") @session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="sub">Jump to sub page</a> <a href="sub">Jump to sub page</a>
@ -199,8 +199,25 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.expects(:get_via_redirect).with("/page/sub", {}) @session.expects(:get_via_redirect).with("/page/sub", {})
@session.clicks_link "Jump to sub page" @session.clicks_link "Jump to sub page"
end end
it "should follow fully qualified local links" do
@response.stubs(:body).returns(<<-EOS)
<a href="http://www.example.com/page/sub">Jump to sub page</a>
EOS
@session.expects(:get_via_redirect).with("/page/sub", {})
@session.clicks_link "Jump to sub page"
end
def test_should_follow_query_parameters it "should follow fully qualified secure local links" do
@response.stubs(:body).returns(<<-EOS)
<a href="https://www.example.com/page/sub">Jump to sub page</a>
EOS
@session.expects(:https!).with(true)
@session.expects(:get_via_redirect).with("/page/sub", {})
@session.clicks_link "Jump to sub page"
end
it "should follow query parameters" do
@session.current_page.stubs(:url).returns("/page") @session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<a href="?foo=bar">Jump to foo bar</a> <a href="?foo=bar">Jump to foo bar</a>

View File

@ -1,14 +1,14 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class FillsInTest < Test::Unit::TestCase describe "fills_in" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_work_with_textareas it "should work with textareas" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_text">User Text</label> <label for="user_text">User Text</label>
@ -21,7 +21,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_password_fields it "should work with password fields" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_text" name="user[text]" type="password" /> <input id="user_text" name="user[text]" type="password" />
@ -33,18 +33,16 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_fail_if_input_not_found it "should fail if input not found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error
@session.fills_in "Email", :with => "foo@example.com"
end
end end
def test_should_allow_overriding_default_form_values it "should allow overriding default form values" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>
@ -57,7 +55,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_choose_the_shortest_label_match it "should choose the shortest label match" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_mail1">Some other mail</label> <label for="user_mail1">Some other mail</label>
@ -73,7 +71,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_choose_the_first_label_match_if_closest_is_a_tie it "should choose the first label match if closest is a tie" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_mail1">Some mail one</label> <label for="user_mail1">Some mail one</label>
@ -89,7 +87,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_anchor_label_matches_to_start_of_label it "should anchor label matches to start of label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Some mail</label> <label for="user_email">Some mail</label>
@ -97,10 +95,10 @@ class FillsInTest < Test::Unit::TestCase
</form> </form>
EOS EOS
assert_raises(RuntimeError) { @session.fills_in "mail", :with => "value" } lambda { @session.fills_in "mail", :with => "value" }.should raise_error
end end
def test_should_anchor_label_matches_to_word_boundaries it "should anchor label matches to word boundaries" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Emailtastic</label> <label for="user_email">Emailtastic</label>
@ -108,10 +106,10 @@ class FillsInTest < Test::Unit::TestCase
</form> </form>
EOS EOS
assert_raises(RuntimeError) { @session.fills_in "Email", :with => "value" } lambda { @session.fills_in "Email", :with => "value" }.should raise_error
end end
def test_should_work_with_inputs_nested_in_labels it "should work with inputs nested in labels" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label> <label>
@ -126,7 +124,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_full_input_names it "should work with full input names" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_email" name="user[email]" type="text" /> <input id="user_email" name="user[email]" type="text" />
@ -138,7 +136,7 @@ class FillsInTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_symbols it "should work with symbols" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>

1
spec/rcov.opts Normal file
View File

@ -0,0 +1 @@
-x gems,spec

View File

@ -1,10 +1,9 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT) RAILS_ROOT = "." unless defined?(RAILS_ROOT)
class ReloadsTest < Test::Unit::TestCase describe "reloads" do
before do
def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@ -13,13 +12,13 @@ class ReloadsTest < Test::Unit::TestCase
@response.stubs(:body).returns("") @response.stubs(:body).returns("")
end end
def test_should_reload_the_page it "should reload the page" do
@session.expects(:get_via_redirect).with("/", {}).times(2) @session.expects(:get_via_redirect).with("/", {}).times(2)
@session.visits("/") @session.visits("/")
@session.reloads @session.reloads
end end
def test_should_not_request_page_if_not_visited_any_page it "should not request page if not visited any page" do
@session.expects(:get_via_redirect).never @session.expects(:get_via_redirect).never
@session.reloads @session.reloads
end end

View File

@ -1,51 +1,45 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
class SelectsTest < Test::Unit::TestCase describe "selects" do
def setup before do
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock) @session.stubs(:response).returns(@response=mock)
end end
def test_should_fail_if_option_not_found it "should fail if option not found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.selects "February", :from => "month" }.should raise_error
@session.selects "February", :from => "month"
end
end end
def test_should_fail_if_option_not_found_in_list_specified_by_element_name it "should fail if option not found in list specified by element name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
<select name="year"><option value="2008">2008</option></select> <select name="year"><option value="2008">2008</option></select>
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.selects "February", :from => "year" }.should raise_error
@session.selects "February", :from => "year"
end
end end
def test_should_fail_if_specified_list_not_found it "should fail if specified list not found" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
</form> </form>
EOS EOS
assert_raises RuntimeError do lambda { @session.selects "February", :from => "year" }.should raise_error
@session.selects "February", :from => "year"
end
end end
def test_should_send_value_from_option it "should send value from option" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
@ -57,7 +51,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_empty_select_lists it "should work with empty select lists" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"></select> <select name="month"></select>
@ -68,7 +62,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_without_specifying_the_field_name_or_label it "should work without specifying the field name or label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
@ -80,7 +74,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_value_from_option_in_list_specified_by_name it "should send value from option in list specified by name" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="start_month"><option value="s1">January</option></select> <select name="start_month"><option value="s1">January</option></select>
@ -93,7 +87,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_send_value_from_option_in_list_specified_by_label it "should send value from option in list specified by label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="start_month">Start Month</label> <label for="start_month">Start Month</label>
@ -108,7 +102,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_use_option_text_if_no_value it "should use option text if no value" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
@ -120,7 +114,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_find_option_by_regexp it "should find option by regexp" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
@ -132,7 +126,7 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_find_option_by_regexp_in_list_specified_by_label it "should find option by regexp in list specified by label" do
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">
<label for="start_month">Start Month</label> <label for="start_month">Start Month</label>

0
spec/spec.opts Normal file
View File

View File

@ -1,5 +1,5 @@
require "rubygems" require "rubygems"
require "test/unit" require "spec"
# gem install redgreen for colored test output # gem install redgreen for colored test output
begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
require "mocha" require "mocha"
@ -17,4 +17,8 @@ class ActionController::Integration::Session
def flunk(message) def flunk(message)
raise message raise message
end end
end
Spec::Runner.configure do |config|
config.mock_with :mocha
end end

View File

@ -1,10 +1,9 @@
require File.dirname(__FILE__) + "/helper" require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT) RAILS_ROOT = "." unless defined?(RAILS_ROOT)
class VisitsTest < Test::Unit::TestCase describe "visits" do
before do
def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
@session.stubs(:assert_response) @session.stubs(:assert_response)
@session.stubs(:get_via_redirect) @session.stubs(:get_via_redirect)
@ -13,19 +12,17 @@ class VisitsTest < Test::Unit::TestCase
@response.stubs(:body).returns("") @response.stubs(:body).returns("")
end end
def test_should_use_get it "should use get" do
@session.expects(:get_via_redirect).with("/", {}) @session.expects(:get_via_redirect).with("/", {})
@session.visits("/") @session.visits("/")
end end
def test_should_assert_valid_response it "should assert valid response" do
@session.expects(:assert_response).with(:success) @session.expects(:assert_response).with(:success)
@session.visits("/") @session.visits("/")
end end
def test_should_require_a_visit_before_manipulating_page it "should require a visit before manipulating page" do
assert_raise(RuntimeError) do lambda { @session.fills_in "foo", :with => "blah" }.should raise_error
@session.fills_in "foo", :with => "blah"
end
end end
end end