Added prelimary support for fully qualified links starting with http:// or https://. Restored missing commits(???)
This commit is contained in:
parent
2ef317f2cf
commit
73d3b72108
@ -2,9 +2,11 @@
|
||||
|
||||
* Enhancements
|
||||
|
||||
* Support file fields using attaches_file (Patch from Kyle Hargraves)
|
||||
* Support button elements (Patch from Nick Sieger)
|
||||
* Support matching select options by regexp (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
|
||||
|
||||
@ -26,7 +28,7 @@
|
||||
* 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)
|
||||
* 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)
|
||||
* 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)
|
||||
|
65
README.txt
65
README.txt
@ -1,14 +1,14 @@
|
||||
= Webrat - Ruby Acceptance Testing for Web applications
|
||||
Webrat
|
||||
======
|
||||
|
||||
http://rubyforge.org/projects/webrat
|
||||
http://github.com/brynary/webrat
|
||||
- [Code on GitHub](http://github.com/brynary/webrat)
|
||||
- [Tickets on Lighthouse](http://webrat.lighthouseapp.com/)
|
||||
|
||||
* mailto:bryan@brynary.com
|
||||
* mailto:seth@mojodna.net
|
||||
Description
|
||||
-----------
|
||||
|
||||
== DESCRIPTION:
|
||||
|
||||
Webrat lets you quickly write robust and thorough acceptance tests for a Ruby
|
||||
Webrat (_Ruby Acceptance Testing for Web applications_)
|
||||
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
|
||||
in-browser testing solution without the associated performance hit (and
|
||||
browser dependency). The result is tests that are less fragile and more
|
||||
@ -19,11 +19,12 @@ Selenium, the primary consideration should be how much JavaScript the
|
||||
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
|
||||
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
|
||||
visits "/"
|
||||
@ -50,25 +51,23 @@ Behind the scenes, this will perform the following work:
|
||||
Take special note of the things _not_ specified in that test, that might cause
|
||||
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
|
||||
* 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.)
|
||||
* The URLs of links followed
|
||||
* The URL the form submission should be sent to, which could change if you
|
||||
- The URLs of links followed
|
||||
- The URL the form submission should be sent to, which could change if you
|
||||
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
|
||||
* Hpricot >= 0.6
|
||||
* Rails integration tests in Test::Unit _or_
|
||||
* RSpec stories (using an RSpec version >= revision 2997)
|
||||
To install the latest release:
|
||||
|
||||
== INSTALL:
|
||||
sudo gem install webrat
|
||||
|
||||
In your stories/helper.rb:
|
||||
|
||||
@ -76,11 +75,23 @@ In your stories/helper.rb:
|
||||
|
||||
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.
|
||||
See MIT-LICENSE in this directory.
|
||||
See MIT-LICENSE.txt in this directory.
|
||||
|
42
Rakefile
42
Rakefile
@ -1,5 +1,7 @@
|
||||
require 'rubygems'
|
||||
require 'hoe'
|
||||
require 'spec'
|
||||
require 'spec/rake/spectask'
|
||||
require './lib/webrat.rb'
|
||||
|
||||
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.remote_rdoc_dir = '' # Release to root
|
||||
p.test_globs = ['test/**/*_test.rb']
|
||||
end
|
||||
|
||||
desc "Upload rdoc to brynary.com"
|
||||
task :publish_rdoc => :docs do
|
||||
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
|
@ -35,7 +35,7 @@ module ActionController
|
||||
current_page.save_and_open
|
||||
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|
|
||||
current_page.send(method_name, *args)
|
||||
end
|
||||
|
@ -97,6 +97,21 @@ module Webrat
|
||||
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
|
||||
|
||||
class ButtonField < Field
|
||||
@ -221,6 +236,15 @@ module Webrat
|
||||
end
|
||||
|
||||
class FileField < Field
|
||||
|
||||
def to_param
|
||||
if @value.nil?
|
||||
super
|
||||
else
|
||||
replace_param_value(super, @value, ActionController::TestUploadedFile.new(@value))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class TextField < Field
|
||||
|
@ -10,6 +10,7 @@ module Webrat
|
||||
method ||= http_method
|
||||
return if href =~ /^#/ && method == :get
|
||||
|
||||
update_protocol(href)
|
||||
Page.new(@page.session, absolute_href, method, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token})
|
||||
end
|
||||
|
||||
@ -27,8 +28,18 @@ module Webrat
|
||||
@element["href"]
|
||||
end
|
||||
|
||||
def update_protocol(href)
|
||||
if href =~ /^https:/
|
||||
@page.session.https!(true)
|
||||
elsif href =~ /^http:/
|
||||
@page.session.https!(false)
|
||||
end
|
||||
end
|
||||
|
||||
def absolute_href
|
||||
if href =~ /^\?/
|
||||
if href =~ %r{^https?://www.example.com(/.*)}
|
||||
$LAST_MATCH_INFO.captures.first
|
||||
elsif href =~ /^\?/
|
||||
"#{@page.url}#{href}"
|
||||
elsif href !~ /^\//
|
||||
"#{@page.url}/#{href}"
|
||||
|
@ -88,6 +88,17 @@ module Webrat
|
||||
option.choose
|
||||
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
|
||||
# web browser if on OS X. Useful for debugging.
|
||||
#
|
||||
|
62
spec/attaches_file_spec.rb
Normal file
62
spec/attaches_file_spec.rb
Normal 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
|
@ -1,37 +1,33 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
class ChecksTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe "checks" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@session.stubs(:response).returns(@response=mock)
|
||||
end
|
||||
|
||||
def test_should_fail_if_no_checkbox_found
|
||||
it "should fail if no checkbox found" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.checks "remember_me"
|
||||
end
|
||||
lambda { @session.checks "remember_me" }.should raise_error
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="text" name="remember_me" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.checks "remember_me"
|
||||
end
|
||||
lambda { @session.checks "remember_me" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_check_rails_style_checkboxes
|
||||
it "should check rails style checkboxes" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
|
||||
@ -45,7 +41,7 @@ class ChecksTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="remember_me" />
|
||||
@ -57,7 +53,7 @@ class ChecksTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="remember_me" value="yes" />
|
||||
@ -70,38 +66,34 @@ class ChecksTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
class UnchecksTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe "unchecks" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@session.stubs(:response).returns(@response=mock)
|
||||
end
|
||||
|
||||
def test_should_fail_if_no_checkbox_found
|
||||
it "should fail if no checkbox found" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.unchecks "remember_me"
|
||||
end
|
||||
lambda { @session.unchecks "remember_me" }.should raise_error
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="text" name="remember_me" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.unchecks "remember_me"
|
||||
end
|
||||
lambda { @session.unchecks "remember_me" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_uncheck_rails_style_checkboxes
|
||||
it "should uncheck rails style checkboxes" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<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
|
||||
end
|
||||
|
||||
def test_should_result_in_value_not_being_posted
|
||||
it "should result in value not being posted" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="remember_me" value="yes" checked="checked" />
|
@ -1,38 +1,33 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
class ChoosesTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
describe "chooses" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@session.stubs(:response).returns(@response=mock)
|
||||
end
|
||||
|
||||
def test_should_fail_if_no_radio_buttons_found
|
||||
it "should fail if no radio buttons found" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.chooses "first option"
|
||||
end
|
||||
lambda { @session.chooses "first option" }.should raise_error
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="text" name="first_option" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.chooses "first_option"
|
||||
end
|
||||
lambda { @session.chooses "first_option" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_check_rails_style_radio_buttons
|
||||
it "should check rails style radio buttons" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||
@ -47,7 +42,7 @@ class ChoosesTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_only_submit_last_chosen_value
|
||||
it "should only submit last chosen value" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||
@ -63,7 +58,7 @@ class ChoosesTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="radio" name="first_option" />
|
||||
@ -75,7 +70,7 @@ class ChoosesTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<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.clicks_button
|
||||
end
|
||||
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
class ClicksButtonTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe "clicks_button" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@ -11,29 +11,25 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.stubs(:response).returns(@response)
|
||||
end
|
||||
|
||||
def test_should_fail_if_no_buttons
|
||||
it "should fail if no buttons" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login"></form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.clicks_button
|
||||
end
|
||||
lambda { @session.clicks_button }.should raise_error
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<input type="reset" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.clicks_button
|
||||
end
|
||||
lambda { @session.clicks_button }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_default_to_get_method
|
||||
it "should default to get method" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form action="/login">
|
||||
<input type="submit" />
|
||||
@ -43,7 +39,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_assert_valid_response
|
||||
it "should assert valid response" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form action="/login">
|
||||
<input type="submit" />
|
||||
@ -53,7 +49,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_default_to_current_url
|
||||
it "should default to current url" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get">
|
||||
<input type="submit" />
|
||||
@ -64,7 +60,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_submit_the_first_form_by_default
|
||||
it "should submit the first form by default" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/form1">
|
||||
<input type="submit" />
|
||||
@ -77,7 +73,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_not_explode_on_file_fields
|
||||
it "should not explode on file fields" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/form1">
|
||||
<input type="file" />
|
||||
@ -87,7 +83,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="get" action="/form1">
|
||||
<input type="submit" />
|
||||
@ -100,7 +96,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button "Form2"
|
||||
end
|
||||
|
||||
def test_should_use_action_from_form
|
||||
it "should use action from form" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input type="submit" />
|
||||
@ -110,7 +106,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_use_method_from_form
|
||||
it "should use method from form" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<input type="submit" />
|
||||
@ -120,7 +116,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="submit" name="cancel" value="Cancel" />
|
||||
@ -131,7 +127,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button("Login")
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<input type="submit" name="cancel" value="Cancel" />
|
||||
@ -142,7 +138,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button("Login")
|
||||
end
|
||||
|
||||
def test_should_send_default_password_field_values
|
||||
it "should send default password field values" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_password" name="user[password]" value="mypass" type="password" />
|
||||
@ -153,7 +149,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_send_default_hidden_field_values
|
||||
it "should send default hidden field values" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<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
|
||||
end
|
||||
|
||||
def test_should_send_default_text_field_values
|
||||
it "should send default text field values" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<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
|
||||
end
|
||||
|
||||
def test_should_send_default_checked_fields
|
||||
it "should send default checked fields" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<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
|
||||
end
|
||||
|
||||
def test_should_send_default_radio_options
|
||||
it "should send default radio options" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||
@ -200,7 +196,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
|
||||
@ -212,7 +208,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<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
|
||||
end
|
||||
|
||||
def test_should_send_default_collection_fields
|
||||
it "should send default collection fields" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="options[]" value="burger" checked="checked" />
|
||||
@ -246,7 +242,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_not_send_default_unchecked_fields
|
||||
it "should not send default unchecked fields" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" value="1" type="checkbox" />
|
||||
@ -257,7 +253,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_send_default_textarea_values
|
||||
it "should send default textarea values" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/posts">
|
||||
<textarea name="post[body]">Post body here!</textarea>
|
||||
@ -268,7 +264,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<select name="month">
|
||||
@ -282,7 +278,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<select name="month">
|
||||
@ -296,7 +292,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<select name="month">
|
||||
@ -310,7 +306,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_handle_nested_properties
|
||||
it "should handle nested properties" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<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
|
||||
end
|
||||
|
||||
def test_should_send_default_empty_text_field_values
|
||||
it "should send default empty text field values" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="" type="text" />
|
||||
@ -333,7 +329,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_recognize_button_tags
|
||||
it "should recognize button tags" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="" type="text" />
|
||||
@ -344,7 +340,7 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_recognize_button_tags_by_content
|
||||
it "should recognize button tags by content" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="" type="text" />
|
@ -1,14 +1,14 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
class ClicksLinkTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe "clicks_link" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@session.stubs(:response).returns(@response=mock)
|
||||
end
|
||||
|
||||
def test_should_use_get_by_default
|
||||
it "should use get by default" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -16,7 +16,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_click_get_links
|
||||
it "should click get links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -24,7 +24,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_get_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_click_delete_links
|
||||
it "should click delete links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -32,7 +32,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_delete_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_click_post_links
|
||||
it "should click post links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -40,7 +40,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_post_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_click_put_links
|
||||
it "should click put links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -48,7 +48,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_put_link "Link text"
|
||||
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)
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
@ -67,7 +67,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Posts"
|
||||
end
|
||||
|
||||
def test_should_click_rails_javascript_delete_links
|
||||
it "should click rails javascript delete links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/posts/1" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
@ -86,7 +86,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Delete"
|
||||
end
|
||||
|
||||
def test_should_click_rails_javascript_post_links
|
||||
it "should click rails javascript post links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
@ -100,7 +100,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Posts"
|
||||
end
|
||||
|
||||
def test_should_click_rails_javascript_put_links
|
||||
it "should click rails javascript put links" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
@ -119,7 +119,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Put"
|
||||
end
|
||||
|
||||
def test_should_assert_valid_response
|
||||
it "should assert valid response" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -127,7 +127,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_not_be_case_sensitive
|
||||
it "should not be case sensitive" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@ -135,7 +135,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "LINK TEXT"
|
||||
end
|
||||
|
||||
def test_should_match_link_substrings
|
||||
it "should match link substrings" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page">This is some cool link text, isn't it?</a>
|
||||
EOS
|
||||
@ -143,7 +143,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_work_with_elements_in_the_link
|
||||
it "should work with elements in the link" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page"><span>Link text</span></a>
|
||||
EOS
|
||||
@ -151,7 +151,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_match_the_first_matching_link
|
||||
it "should match the first matching link" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page1">Link text</a>
|
||||
<a href="/page2">Link text</a>
|
||||
@ -160,7 +160,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
def test_should_choose_the_shortest_link_text_match
|
||||
it "should choose the shortest link text match" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page1">Linkerama</a>
|
||||
<a href="/page2">Link</a>
|
||||
@ -170,7 +170,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Link"
|
||||
end
|
||||
|
||||
def test_should_click_link_within_a_selector
|
||||
it "should click link within a selector" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="/page1">Link</a>
|
||||
<div id="container">
|
||||
@ -182,7 +182,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link_within "#container", "Link"
|
||||
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)
|
||||
<a href="#section-1">Jump to Section 1</a>
|
||||
EOS
|
||||
@ -191,7 +191,7 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Jump to Section 1"
|
||||
end
|
||||
|
||||
def test_should_follow_relative_links
|
||||
it "should follow relative links" do
|
||||
@session.current_page.stubs(:url).returns("/page")
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="sub">Jump to sub page</a>
|
||||
@ -200,7 +200,24 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||
@session.clicks_link "Jump to sub page"
|
||||
end
|
||||
|
||||
def test_should_follow_query_parameters
|
||||
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
|
||||
|
||||
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")
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<a href="?foo=bar">Jump to foo bar</a>
|
@ -1,14 +1,14 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
class FillsInTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe "fills_in" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@session.stubs(:response).returns(@response=mock)
|
||||
end
|
||||
|
||||
def test_should_work_with_textareas
|
||||
it "should work with textareas" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_text">User Text</label>
|
||||
@ -21,7 +21,7 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_work_with_password_fields
|
||||
it "should work with password fields" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<input id="user_text" name="user[text]" type="password" />
|
||||
@ -33,18 +33,16 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_fail_if_input_not_found
|
||||
it "should fail if input not found" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.fills_in "Email", :with => "foo@example.com"
|
||||
end
|
||||
lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_allow_overriding_default_form_values
|
||||
it "should allow overriding default form values" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Email</label>
|
||||
@ -57,7 +55,7 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_choose_the_shortest_label_match
|
||||
it "should choose the shortest label match" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_mail1">Some other mail</label>
|
||||
@ -73,7 +71,7 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_mail1">Some mail one</label>
|
||||
@ -89,7 +87,7 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Some mail</label>
|
||||
@ -97,10 +95,10 @@ class FillsInTest < Test::Unit::TestCase
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises(RuntimeError) { @session.fills_in "mail", :with => "value" }
|
||||
lambda { @session.fills_in "mail", :with => "value" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_anchor_label_matches_to_word_boundaries
|
||||
it "should anchor label matches to word boundaries" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Emailtastic</label>
|
||||
@ -108,10 +106,10 @@ class FillsInTest < Test::Unit::TestCase
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises(RuntimeError) { @session.fills_in "Email", :with => "value" }
|
||||
lambda { @session.fills_in "Email", :with => "value" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_work_with_inputs_nested_in_labels
|
||||
it "should work with inputs nested in labels" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<label>
|
||||
@ -126,7 +124,7 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_work_with_full_input_names
|
||||
it "should work with full input names" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<input id="user_email" name="user[email]" type="text" />
|
||||
@ -138,7 +136,7 @@ class FillsInTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_work_with_symbols
|
||||
it "should work with symbols" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Email</label>
|
1
spec/rcov.opts
Normal file
1
spec/rcov.opts
Normal file
@ -0,0 +1 @@
|
||||
-x gems,spec
|
@ -1,10 +1,9 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
|
||||
|
||||
class ReloadsTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
describe "reloads" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@ -13,13 +12,13 @@ class ReloadsTest < Test::Unit::TestCase
|
||||
@response.stubs(:body).returns("")
|
||||
end
|
||||
|
||||
def test_should_reload_the_page
|
||||
it "should reload the page" do
|
||||
@session.expects(:get_via_redirect).with("/", {}).times(2)
|
||||
@session.visits("/")
|
||||
@session.reloads
|
||||
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.reloads
|
||||
end
|
@ -1,26 +1,24 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
class SelectsTest < Test::Unit::TestCase
|
||||
def setup
|
||||
describe "selects" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@session.stubs(:response).returns(@response=mock)
|
||||
end
|
||||
|
||||
def test_should_fail_if_option_not_found
|
||||
it "should fail if option not found" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.selects "February", :from => "month"
|
||||
end
|
||||
lambda { @session.selects "February", :from => "month" }.should raise_error
|
||||
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)
|
||||
<form method="get" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
@ -28,24 +26,20 @@ class SelectsTest < Test::Unit::TestCase
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.selects "February", :from => "year"
|
||||
end
|
||||
lambda { @session.selects "February", :from => "year" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_fail_if_specified_list_not_found
|
||||
it "should fail if specified list not found" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="get" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
</form>
|
||||
EOS
|
||||
|
||||
assert_raises RuntimeError do
|
||||
@session.selects "February", :from => "year"
|
||||
end
|
||||
lambda { @session.selects "February", :from => "year" }.should raise_error
|
||||
end
|
||||
|
||||
def test_should_send_value_from_option
|
||||
it "should send value from option" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
@ -57,7 +51,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_work_with_empty_select_lists
|
||||
it "should work with empty select lists" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<select name="month"></select>
|
||||
@ -68,7 +62,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
@ -80,7 +74,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<select name="start_month"><option value="s1">January</option></select>
|
||||
@ -93,7 +87,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<label for="start_month">Start Month</label>
|
||||
@ -108,7 +102,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_use_option_text_if_no_value
|
||||
it "should use option text if no value" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option>January</option></select>
|
||||
@ -120,7 +114,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
def test_should_find_option_by_regexp
|
||||
it "should find option by regexp" do
|
||||
@response.stubs(:body).returns(<<-EOS)
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option>January</option></select>
|
||||
@ -132,7 +126,7 @@ class SelectsTest < Test::Unit::TestCase
|
||||
@session.clicks_button
|
||||
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)
|
||||
<form method="post" action="/login">
|
||||
<label for="start_month">Start Month</label>
|
0
spec/spec.opts
Normal file
0
spec/spec.opts
Normal file
@ -1,5 +1,5 @@
|
||||
require "rubygems"
|
||||
require "test/unit"
|
||||
require "spec"
|
||||
# gem install redgreen for colored test output
|
||||
begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
|
||||
require "mocha"
|
||||
@ -18,3 +18,7 @@ class ActionController::Integration::Session
|
||||
raise message
|
||||
end
|
||||
end
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
@ -1,10 +1,9 @@
|
||||
require File.dirname(__FILE__) + "/helper"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
||||
|
||||
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
|
||||
|
||||
class VisitsTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
describe "visits" do
|
||||
before do
|
||||
@session = ActionController::Integration::Session.new
|
||||
@session.stubs(:assert_response)
|
||||
@session.stubs(:get_via_redirect)
|
||||
@ -13,19 +12,17 @@ class VisitsTest < Test::Unit::TestCase
|
||||
@response.stubs(:body).returns("")
|
||||
end
|
||||
|
||||
def test_should_use_get
|
||||
it "should use get" do
|
||||
@session.expects(:get_via_redirect).with("/", {})
|
||||
@session.visits("/")
|
||||
end
|
||||
|
||||
def test_should_assert_valid_response
|
||||
it "should assert valid response" do
|
||||
@session.expects(:assert_response).with(:success)
|
||||
@session.visits("/")
|
||||
end
|
||||
|
||||
def test_should_require_a_visit_before_manipulating_page
|
||||
assert_raise(RuntimeError) do
|
||||
@session.fills_in "foo", :with => "blah"
|
||||
end
|
||||
it "should require a visit before manipulating page" do
|
||||
lambda { @session.fills_in "foo", :with => "blah" }.should raise_error
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user