mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-16 04:08:08 +01:00
Added Rspec and Webrat plugins and started porting Selenium on Rails tests to Rspec Plain Text Stories driving Webrat driving Selenium.
This commit is contained in:
parent
7b432a74ed
commit
2c09db45c5
602 changed files with 47788 additions and 29 deletions
59
vendor/plugins/webrat/spec/api/attaches_file_spec.rb
vendored
Normal file
59
vendor/plugins/webrat/spec/api/attaches_file_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "attaches_file" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
|
||||
@filename = __FILE__
|
||||
@uploaded_file = mock
|
||||
ActionController::TestUploadedFile.stubs(:new).returns(@uploaded_file)
|
||||
end
|
||||
|
||||
it "should fail if no file field found" do
|
||||
@session.response_body = <<-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
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/widgets">
|
||||
<input type="file" id="widget_file" name="widget[file]" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/widgets", { "widget" => { "file" => "" } })
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should submit the attached file" do
|
||||
@session.response_body = <<-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).with("/widgets", { "widget" => { "file" => @uploaded_file } })
|
||||
@session.attaches_file "Document", @filename
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should support collections" do
|
||||
@session.response_body = <<-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).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } })
|
||||
@session.attaches_file "Document", @filename
|
||||
@session.attaches_file "Spreadsheet", @filename
|
||||
@session.clicks_button
|
||||
end
|
||||
end
|
||||
116
vendor/plugins/webrat/spec/api/checks_spec.rb
vendored
Normal file
116
vendor/plugins/webrat/spec/api/checks_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "checks" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should fail if no checkbox found" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.checks "remember_me" }.should raise_error
|
||||
end
|
||||
|
||||
it "should fail if input is not a checkbox" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="text" name="remember_me" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.checks "remember_me" }.should raise_error
|
||||
end
|
||||
|
||||
it "should check rails style checkboxes" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
|
||||
<input name="user[tos]" type="hidden" value="0" />
|
||||
<label for="user_tos">TOS</label>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"tos" => "1"})
|
||||
@session.checks "TOS"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should result in the value on being posted if not specified" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="remember_me" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "remember_me" => "on")
|
||||
@session.checks "remember_me"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should result in a custom value being posted" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="remember_me" value="yes" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "remember_me" => "yes")
|
||||
@session.checks "remember_me"
|
||||
@session.clicks_button
|
||||
end
|
||||
end
|
||||
|
||||
describe "unchecks" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should fail if no checkbox found" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.unchecks "remember_me" }.should raise_error
|
||||
end
|
||||
|
||||
it "should fail if input is not a checkbox" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="text" name="remember_me" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.unchecks "remember_me" }.should raise_error
|
||||
end
|
||||
|
||||
it "should uncheck rails style checkboxes" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
|
||||
<input name="user[tos]" type="hidden" value="0" />
|
||||
<label for="user_tos">TOS</label>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"tos" => "0"})
|
||||
@session.checks "TOS"
|
||||
@session.unchecks "TOS"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should result in value not being posted" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="remember_me" value="yes" checked="checked" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", {})
|
||||
@session.unchecks "remember_me"
|
||||
@session.clicks_button
|
||||
end
|
||||
end
|
||||
80
vendor/plugins/webrat/spec/api/chooses_spec.rb
vendored
Normal file
80
vendor/plugins/webrat/spec/api/chooses_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "chooses" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should fail if no radio buttons found" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.chooses "first option" }.should raise_error
|
||||
end
|
||||
|
||||
it "should fail if input is not a radio button" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="text" name="first_option" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.chooses "first_option" }.should raise_error
|
||||
end
|
||||
|
||||
it "should check rails style radio buttons" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||
<label for="user_gender_male">Male</label>
|
||||
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
|
||||
<label for="user_gender_female">Female</label>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"gender" => "M"})
|
||||
@session.chooses "Male"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should only submit last chosen value" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||
<label for="user_gender_male">Male</label>
|
||||
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
|
||||
<label for="user_gender_female">Female</label>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"gender" => "M"})
|
||||
@session.chooses "Female"
|
||||
@session.chooses "Male"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should result in the value on being posted if not specified" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="radio" name="first_option" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "first_option" => "on")
|
||||
@session.chooses "first_option"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should result in the value on being posted if not specified and checked by default" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="radio" name="first_option" checked="checked"/>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "first_option" => "on")
|
||||
@session.clicks_button
|
||||
end
|
||||
end
|
||||
336
vendor/plugins/webrat/spec/api/clicks_button_spec.rb
vendored
Normal file
336
vendor/plugins/webrat/spec/api/clicks_button_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,336 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "clicks_button" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should fail if no buttons" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login"></form>
|
||||
EOS
|
||||
|
||||
lambda { @session.clicks_button }.should raise_error
|
||||
end
|
||||
|
||||
it "should fail if input is not a submit button" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input type="reset" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.clicks_button }.should raise_error
|
||||
end
|
||||
|
||||
it "should default to get method" do
|
||||
@session.response_body = <<-EOS
|
||||
<form action="/login">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get)
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should assert valid response" do
|
||||
@session.response_body = <<-EOS
|
||||
<form action="/login">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.response_code = 404
|
||||
lambda { @session.clicks_button }.should raise_error
|
||||
end
|
||||
|
||||
it "should submit the first form by default" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/form1">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
<form method="get" action="/form2">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/form1", {})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should not explode on file fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/form1">
|
||||
<input type="file" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should submit the form with the specified button" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/form1">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
<form method="get" action="/form2">
|
||||
<input type="submit" value="Form2" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/form2", {})
|
||||
@session.clicks_button "Form2"
|
||||
end
|
||||
|
||||
it "should use action from form" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", {})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should use method from form" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post)
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send button as param if it has a name" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="submit" name="cancel" value="Cancel" />
|
||||
<input type="submit" name="login" value="Login" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "login" => "Login")
|
||||
@session.clicks_button("Login")
|
||||
end
|
||||
|
||||
it "should not send button as param if it has no name" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="submit" name="cancel" value="Cancel" />
|
||||
<input type="submit" value="Login" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", {})
|
||||
@session.clicks_button("Login")
|
||||
end
|
||||
|
||||
it "should send default password field values" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_password" name="user[password]" value="mypass" type="password" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"password" => "mypass"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default hidden field values" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"email" => "test@example.com"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default text field values" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"email" => "test@example.com"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default checked fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"tos" => "1"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default radio options" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||
<label for="user_gender_male">Male</label>
|
||||
<input id="user_gender_female" name="user[gender]" type="radio" value="F" checked="checked" />
|
||||
<label for="user_gender_female">Female</label>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"gender" => "F"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send correct data for rails style unchecked fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
|
||||
<input name="user[tos]" type="hidden" value="0" /> TOS
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"tos" => "0"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send correct data for rails style checked fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
|
||||
<input name="user[tos]" type="hidden" value="0" /> TOS
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"tos" => "1"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default collection fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="checkbox" name="options[]" value="burger" checked="checked" />
|
||||
<input type="radio" name="options[]" value="fries" checked="checked" />
|
||||
<input type="text" name="options[]" value="soda" />
|
||||
<!-- Same value appearing twice -->
|
||||
<input type="text" name="options[]" value="soda" />
|
||||
<input type="hidden" name="options[]" value="dessert" />
|
||||
<input type="hidden" name="response[choices][][selected]" value="one" />
|
||||
<input type="hidden" name="response[choices][][selected]" value="two" />
|
||||
<!-- Same value appearing twice -->
|
||||
<input type="hidden" name="response[choices][][selected]" value="two" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login",
|
||||
"options" => ["burger", "fries", "soda", "soda", "dessert"],
|
||||
"response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should not send default unchecked fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_tos" name="user[tos]" value="1" type="checkbox" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", {})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default textarea values" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/posts">
|
||||
<textarea name="post[body]">Post body here!</textarea>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/posts", "post" => {"body" => "Post body here!"})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default selected option value from select" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<select name="month">
|
||||
<option value="1">January</option>
|
||||
<option value="2" selected="selected">February</option>
|
||||
</select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "month" => "2")
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default selected option inner html from select when no value attribute" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<select name="month">
|
||||
<option>January</option>
|
||||
<option selected="selected">February</option>
|
||||
</select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "month" => "February")
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send first select option value when no option selected" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<select name="month">
|
||||
<option value="1">January</option>
|
||||
<option value="2">February</option>
|
||||
</select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "month" => "1")
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should handle nested properties" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/>
|
||||
<input type="text" id="contestant_scores_13" name="contestant[scores][3]" value="4"/>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send default empty text field values" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"email" => ""})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should recognize button tags" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="" type="text" />
|
||||
<button type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"email" => ""})
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should recognize button tags by content" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<input id="user_email" name="user[email]" value="" type="text" />
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:get).with("/login", "user" => {"email" => ""})
|
||||
@session.clicks_button "Login"
|
||||
end
|
||||
end
|
||||
216
vendor/plugins/webrat/spec/api/clicks_link_spec.rb
vendored
Normal file
216
vendor/plugins/webrat/spec/api/clicks_link_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "clicks_link" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should use get by default" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page", {})
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
it "should click get links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page", {})
|
||||
@session.clicks_get_link "Link text"
|
||||
end
|
||||
|
||||
it "should click delete links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.expects(:delete).with("/page", {})
|
||||
@session.clicks_delete_link "Link text"
|
||||
end
|
||||
|
||||
it "should click post links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.expects(:post).with("/page", {})
|
||||
@session.clicks_post_link "Link text"
|
||||
end
|
||||
|
||||
it "should click put links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.expects(:put).with("/page", {})
|
||||
@session.clicks_put_link "Link text"
|
||||
end
|
||||
|
||||
it "should click rails javascript links with authenticity tokens" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
this.parentNode.appendChild(f);
|
||||
f.method = 'POST';
|
||||
f.action = this.href;
|
||||
var s = document.createElement('input');
|
||||
s.setAttribute('type', 'hidden');
|
||||
s.setAttribute('name', 'authenticity_token');
|
||||
s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62');
|
||||
f.appendChild(s);
|
||||
f.submit();
|
||||
return false;">Posts</a>
|
||||
EOS
|
||||
@session.expects(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
|
||||
@session.clicks_link "Posts"
|
||||
end
|
||||
|
||||
it "should click rails javascript delete links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/posts/1" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
this.parentNode.appendChild(f);
|
||||
f.method = 'POST';
|
||||
f.action = this.href;
|
||||
var m = document.createElement('input');
|
||||
m.setAttribute('type', 'hidden');
|
||||
m.setAttribute('name', '_method');
|
||||
m.setAttribute('value', 'delete');
|
||||
f.appendChild(m);
|
||||
f.submit();
|
||||
return false;">Delete</a>
|
||||
EOS
|
||||
@session.expects(:delete).with("/posts/1", {})
|
||||
@session.clicks_link "Delete"
|
||||
end
|
||||
|
||||
it "should click rails javascript post links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
this.parentNode.appendChild(f);
|
||||
f.method = 'POST';
|
||||
f.action = this.href;
|
||||
f.submit();
|
||||
return false;">Posts</a>
|
||||
EOS
|
||||
@session.expects(:post).with("/posts", {})
|
||||
@session.clicks_link "Posts"
|
||||
end
|
||||
|
||||
it "should click rails javascript put links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
f.style.display = 'none';
|
||||
this.parentNode.appendChild(f);
|
||||
f.method = 'POST';
|
||||
f.action = this.href;
|
||||
var m = document.createElement('input');
|
||||
m.setAttribute('type', 'hidden');
|
||||
m.setAttribute('name', '_method');
|
||||
m.setAttribute('value', 'put');
|
||||
f.appendChild(m);
|
||||
f.submit();
|
||||
return false;">Put</a></h2>
|
||||
EOS
|
||||
@session.expects(:put).with("/posts", {})
|
||||
@session.clicks_link "Put"
|
||||
end
|
||||
|
||||
it "should assert valid response" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.response_code = 404
|
||||
lambda { @session.clicks_link "Link text" }.should raise_error
|
||||
end
|
||||
|
||||
it "should not be case sensitive" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page", {})
|
||||
@session.clicks_link "LINK TEXT"
|
||||
end
|
||||
|
||||
it "should match link substrings" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page">This is some cool link text, isn't it?</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page", {})
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
it "should work with elements in the link" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page"><span>Link text</span></a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page", {})
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
it "should match the first matching link" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page1">Link text</a>
|
||||
<a href="/page2">Link text</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page1", {})
|
||||
@session.clicks_link "Link text"
|
||||
end
|
||||
|
||||
it "should choose the shortest link text match" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page1">Linkerama</a>
|
||||
<a href="/page2">Link</a>
|
||||
EOS
|
||||
|
||||
@session.expects(:get).with("/page2", {})
|
||||
@session.clicks_link "Link"
|
||||
end
|
||||
|
||||
it "should click link within a selector" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/page1">Link</a>
|
||||
<div id="container">
|
||||
<a href="/page2">Link</a>
|
||||
</div>
|
||||
EOS
|
||||
|
||||
@session.expects(:get).with("/page2", {})
|
||||
@session.clicks_link_within "#container", "Link"
|
||||
end
|
||||
|
||||
it "should not make request when link is local anchor" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="#section-1">Jump to Section 1</a>
|
||||
EOS
|
||||
# Don't know why @session.expects(:get).never doesn't work here
|
||||
@session.expects(:send).with('get_via_redirect', '#section-1', {}).never
|
||||
@session.clicks_link "Jump to Section 1"
|
||||
end
|
||||
|
||||
it "should follow relative links" do
|
||||
@session.current_page.stubs(:url).returns("/page")
|
||||
@session.response_body = <<-EOS
|
||||
<a href="sub">Jump to sub page</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page/sub", {})
|
||||
@session.clicks_link "Jump to sub page"
|
||||
end
|
||||
|
||||
it "should follow fully qualified local links" do
|
||||
@session.response_body = <<-EOS
|
||||
<a href="http://www.example.com/page/sub">Jump to sub page</a>
|
||||
EOS
|
||||
@session.expects(:get).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.response_body = <<-EOS
|
||||
<a href="?foo=bar">Jump to foo bar</a>
|
||||
EOS
|
||||
@session.expects(:get).with("/page?foo=bar", {})
|
||||
@session.clicks_link "Jump to foo bar"
|
||||
end
|
||||
end
|
||||
148
vendor/plugins/webrat/spec/api/fills_in_spec.rb
vendored
Normal file
148
vendor/plugins/webrat/spec/api/fills_in_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "fills_in" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should work with textareas" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_text">User Text</label>
|
||||
<textarea id="user_text" name="user[text]"></textarea>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "user" => {"text" => "filling text area"})
|
||||
@session.fills_in "User Text", :with => "filling text area"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should work with password fields" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input id="user_text" name="user[text]" type="password" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "user" => {"text" => "pass"})
|
||||
@session.fills_in "user_text", :with => "pass"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should fail if input not found" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.fills_in "Email", :with => "foo@example.com" }.should raise_error
|
||||
end
|
||||
|
||||
it "should allow overriding default form values" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Email</label>
|
||||
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||
@session.fills_in "user[email]", :with => "foo@example.com"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should choose the shortest label match" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_mail1">Some other mail</label>
|
||||
<input id="user_mail1" name="user[mail1]" type="text" />
|
||||
<label for="user_mail2">Some mail</label>
|
||||
<input id="user_mail2" name="user[mail2]" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
@session.expects(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"})
|
||||
@session.fills_in "Some", :with => "value"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should choose the first label match if closest is a tie" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_mail1">Some mail one</label>
|
||||
<input id="user_mail1" name="user[mail1]" type="text" />
|
||||
<label for="user_mail2">Some mail two</label>
|
||||
<input id="user_mail2" name="user[mail2]" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
@session.expects(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""})
|
||||
@session.fills_in "Some mail", :with => "value"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should anchor label matches to start of label" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Some mail</label>
|
||||
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.fills_in "mail", :with => "value" }.should raise_error
|
||||
end
|
||||
|
||||
it "should anchor label matches to word boundaries" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Emailtastic</label>
|
||||
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.fills_in "Email", :with => "value" }.should raise_error
|
||||
end
|
||||
|
||||
it "should work with inputs nested in labels" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label>
|
||||
Email
|
||||
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
|
||||
</label>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||
@session.fills_in "Email", :with => "foo@example.com"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should work with full input names" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<input id="user_email" name="user[email]" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||
@session.fills_in "user[email]", :with => "foo@example.com"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should work with symbols" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="user_email">Email</label>
|
||||
<input id="user_email" name="user[email]" type="text" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"})
|
||||
@session.fills_in :email, :with => "foo@example.com"
|
||||
@session.clicks_button
|
||||
end
|
||||
end
|
||||
14
vendor/plugins/webrat/spec/api/reloads_spec.rb
vendored
Normal file
14
vendor/plugins/webrat/spec/api/reloads_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "reloads" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
@session.response_body = "Hello world"
|
||||
end
|
||||
|
||||
it "should reload the page" do
|
||||
@session.expects(:get).with("/", {}).times(2)
|
||||
@session.visits("/")
|
||||
@session.reloads
|
||||
end
|
||||
end
|
||||
53
vendor/plugins/webrat/spec/api/save_and_open_spec.rb
vendored
Normal file
53
vendor/plugins/webrat/spec/api/save_and_open_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "save_and_open_page" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
|
||||
@session.response_body = <<-HTML
|
||||
<html>
|
||||
<head>
|
||||
<link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello world</h1>
|
||||
<img src="/images/bar.png" />
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
|
||||
File.stubs(:exist?).returns(true)
|
||||
Time.stubs(:now).returns(1234)
|
||||
Webrat::Page.any_instance.stubs(:open_in_browser)
|
||||
|
||||
@file_handle = mock()
|
||||
File.stubs(:open).with(filename, 'w').yields(@file_handle)
|
||||
@file_handle.stubs(:write)
|
||||
end
|
||||
|
||||
it "should rewrite css rules" do
|
||||
@file_handle.expects(:write).with do |html|
|
||||
html =~ %r|#{@session.doc_root}/stylesheets/foo.css|s
|
||||
end
|
||||
|
||||
@session.save_and_open_page
|
||||
end
|
||||
|
||||
it "should rewrite image paths" do
|
||||
@file_handle.expects(:write).with do |html|
|
||||
html =~ %r|#{@session.doc_root}/images/bar.png|s
|
||||
end
|
||||
|
||||
@session.save_and_open_page
|
||||
end
|
||||
|
||||
it "should open the temp file in a browser" do
|
||||
Webrat::Page.any_instance.expects(:open_in_browser).with(filename)
|
||||
@session.save_and_open_page
|
||||
end
|
||||
|
||||
def filename
|
||||
File.expand_path("./webrat-#{Time.now}.html")
|
||||
end
|
||||
|
||||
end
|
||||
140
vendor/plugins/webrat/spec/api/selects_spec.rb
vendored
Normal file
140
vendor/plugins/webrat/spec/api/selects_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "selects" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
|
||||
it "should fail if option not found" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.selects "February", :from => "month" }.should raise_error
|
||||
end
|
||||
|
||||
it "should fail if option not found in list specified by element name" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
<select name="year"><option value="2008">2008</option></select>
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.selects "February", :from => "year" }.should raise_error
|
||||
end
|
||||
|
||||
it "should fail if specified list not found" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="get" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
</form>
|
||||
EOS
|
||||
|
||||
lambda { @session.selects "February", :from => "year" }.should raise_error
|
||||
end
|
||||
|
||||
it "should send value from option" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "month" => "1")
|
||||
@session.selects "January", :from => "month"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should work with empty select lists" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="month"></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", 'month' => '')
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should work without specifying the field name or label" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option value="1">January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "month" => "1")
|
||||
@session.selects "January"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send value from option in list specified by name" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="start_month"><option value="s1">January</option></select>
|
||||
<select name="end_month"><option value="e1">January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
|
||||
@session.selects "January", :from => "end_month"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should send value from option in list specified by label" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="start_month">Start Month</label>
|
||||
<select id="start_month" name="start_month"><option value="s1">January</option></select>
|
||||
<label for="end_month">End Month</label>
|
||||
<select id="end_month" name="end_month"><option value="e1">January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
|
||||
@session.selects "January", :from => "End Month"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should use option text if no value" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option>January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "month" => "January")
|
||||
@session.selects "January", :from => "month"
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should find option by regexp" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<select name="month"><option>January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "month" => "January")
|
||||
@session.selects(/jan/i)
|
||||
@session.clicks_button
|
||||
end
|
||||
|
||||
it "should find option by regexp in list specified by label" do
|
||||
@session.response_body = <<-EOS
|
||||
<form method="post" action="/login">
|
||||
<label for="start_month">Start Month</label>
|
||||
<select id="start_month" name="start_month"><option value="s1">January</option></select>
|
||||
<label for="end_month">End Month</label>
|
||||
<select id="end_month" name="end_month"><option value="e1">January</option></select>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
EOS
|
||||
@session.expects(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
|
||||
@session.selects(/jan/i, :from => "End Month")
|
||||
@session.clicks_button
|
||||
end
|
||||
end
|
||||
22
vendor/plugins/webrat/spec/api/visits_spec.rb
vendored
Normal file
22
vendor/plugins/webrat/spec/api/visits_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "visits" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
@session.response_body = "Hello world"
|
||||
end
|
||||
|
||||
it "should use get" do
|
||||
@session.expects(:get).with("/", {})
|
||||
@session.visits("/")
|
||||
end
|
||||
|
||||
it "should assert valid response" do
|
||||
@session.response_code = 404
|
||||
lambda { @session.visits("/") }.should raise_error
|
||||
end
|
||||
|
||||
it "should require a visit before manipulating page" do
|
||||
lambda { @session.fills_in "foo", :with => "blah" }.should raise_error
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue