From 5430930baca8dd3d1c62fda2306b80696fb101b8 Mon Sep 17 00:00:00 2001 From: "mike.gaffney" Date: Mon, 1 Jun 2009 12:17:29 -0500 Subject: [PATCH] added test for clicking link by title --- .../rails/app/controllers/links_controller.rb | 7 +++++++ .../app/controllers/webrat_controller.rb | 20 +++++++++--------- .../rails/app/helpers/links_helper.rb | 2 ++ .../rails/app/views/links/show.html.erb | 4 ++++ spec/integration/rails/config/routes.rb | 1 + .../test/functional/links_controller_test.rb | 8 +++++++ .../rails/test/integration/link_click_test.rb | 21 +++++++++++++++++++ .../rails/test/integration/webrat_test.rb | 12 ----------- 8 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 spec/integration/rails/app/controllers/links_controller.rb create mode 100644 spec/integration/rails/app/helpers/links_helper.rb create mode 100644 spec/integration/rails/app/views/links/show.html.erb create mode 100644 spec/integration/rails/test/functional/links_controller_test.rb create mode 100644 spec/integration/rails/test/integration/link_click_test.rb diff --git a/spec/integration/rails/app/controllers/links_controller.rb b/spec/integration/rails/app/controllers/links_controller.rb new file mode 100644 index 0000000..18860c2 --- /dev/null +++ b/spec/integration/rails/app/controllers/links_controller.rb @@ -0,0 +1,7 @@ +class LinksController < ApplicationController + def show + if params[:value] + render :text => "Link:#{params[:value]}" + end + end +end diff --git a/spec/integration/rails/app/controllers/webrat_controller.rb b/spec/integration/rails/app/controllers/webrat_controller.rb index e9f9ad4..2861d2e 100644 --- a/spec/integration/rails/app/controllers/webrat_controller.rb +++ b/spec/integration/rails/app/controllers/webrat_controller.rb @@ -5,38 +5,38 @@ class FakeModel end class WebratController < ApplicationController - + def form end - + def buttons end - + def submit render :text => "OK Test Link Text" end - + def internal_redirect redirect_to submit_path end - + def infinite_redirect redirect_to infinite_redirect_path end - + def external_redirect redirect_to "http://google.com" end - + def before_redirect_form end - + def redirect_to_show_params redirect_to show_params_path(:custom_param => "123") end - + def show_params render :text => params.to_json end - + end diff --git a/spec/integration/rails/app/helpers/links_helper.rb b/spec/integration/rails/app/helpers/links_helper.rb new file mode 100644 index 0000000..f6bc988 --- /dev/null +++ b/spec/integration/rails/app/helpers/links_helper.rb @@ -0,0 +1,2 @@ +module LinksHelper +end diff --git a/spec/integration/rails/app/views/links/show.html.erb b/spec/integration/rails/app/views/links/show.html.erb new file mode 100644 index 0000000..d1700a3 --- /dev/null +++ b/spec/integration/rails/app/views/links/show.html.erb @@ -0,0 +1,4 @@ +

Webrat Links Page

+LinkByText
+id
+title \ No newline at end of file diff --git a/spec/integration/rails/config/routes.rb b/spec/integration/rails/config/routes.rb index e330d3f..f3a66e6 100644 --- a/spec/integration/rails/config/routes.rb +++ b/spec/integration/rails/config/routes.rb @@ -12,4 +12,5 @@ ActionController::Routing::Routes.draw do |map| webrat.buttons "/buttons", :action => "buttons" webrat.root :action => "form" end + map.resource 'links' end diff --git a/spec/integration/rails/test/functional/links_controller_test.rb b/spec/integration/rails/test/functional/links_controller_test.rb new file mode 100644 index 0000000..688ee9f --- /dev/null +++ b/spec/integration/rails/test/functional/links_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class LinksControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/spec/integration/rails/test/integration/link_click_test.rb b/spec/integration/rails/test/integration/link_click_test.rb new file mode 100644 index 0000000..ebfdefb --- /dev/null +++ b/spec/integration/rails/test/integration/link_click_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +class LinkClickTest < ActionController::IntegrationTest + test "should click link by text" do + visit links_path + click_link "LinkByText" + assert_contain("Link:LinkByText") + end + + test "should click link by id" do + visit links_path + click_link "link_by_id" + assert_contain("Link:link_by_id") + end + + test "should click link by title" do + visit links_path + click_link "LinkByTitle" + assert_contain("Link:LinkByTitle") + end +end \ No newline at end of file diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index 9d858c6..7df1d9c 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -49,18 +49,6 @@ class WebratTest < ActionController::IntegrationTest assert response.redirect? end - test "should click link by text" do - visit internal_redirect_path - click_link "Test Link Text" - assert_contain("Webrat Form") - end - - test "should click link by id" do - visit internal_redirect_path - click_link "link_id" - assert_contain("Webrat Form") - end - test "should be able to assert xpath" do visit root_path assert_have_xpath "//h1"