Here is the error I am getting: .....F Failures: 1) LayoutLinks should have the right links on the layout Failure/Error: click_link "Sign up" Could not find link with text or title or id "Sign up" # ./spec/requests/layout_links_spec.rb:37:in `block (2 levels) in <top (required)>'' Finished in 0.28358 seconds 6 examples, 1 failure Here is the test file for LayoutLinks. The last ''it block'' has the click_link that is giving me the problem: #spec/requests/layout_links_spec.rb: require ''spec_helper'' describe "LayoutLinks" do it "should have a Home page at: /" do get ''/'' response.should have_selector(''title'', :content => "Home") end it "should have an About page at: /about" do get ''/about'' response.should have_selector(''title'', :content => "About") end it "should have a Contact page at: /contact" do get ''/contact'' response.should have_selector(''title'', :content => "Contact") end it "should have a Help page at: /help" do get ''/help'' response.should have_selector(''title'', :content => "Help") end it "should have a Sign up page at: /signup" do get "/signup" response.should have_selector(''title'', :content => "Sign up") end it "should have the right links on the layout" do visit root_path click_link "About" response.should have_selector(''title'', :content => "About") click_link "Contact" response.should have_selector(''title'', :content => "Contact") click_link "Help" response.should have_selector(''title'', :content => "Help") click_link "Sign up" response.should have_selector(''title'', :content => "Sign up") click_link "Home" response.should have_selector(''title'', :content => "Home") end The other click_link''s pass their tests. It''s only the ''Sign up'' link that is giving me the problem. The only difference I can discern is that the page with the ''Sign up'' link is handled by a different controller: Users v. Pages. Here is the application layout: application.html.erb: ------------------- <!DOCTYPE html> <html> <head> <title><%= title() %></title> <%= csrf_meta_tag %> <%= render ''layouts/stylesheets'' %> </head> <body> <div class="container"> <%= render ''layouts/header'' %> <section class="round"> <%= yield %> </section> <%= render ''layouts/footer'' %> </div> </body> </html> Here is the Home page that contains the ''Sign Up'' link: home.html.erb: (inserted at ''yield'' in application layout) -------------- <h1>Me</h1> <p>Hi, this is my website.</p> <%= link_to "Sign up", signup_path, :class => "signup_button round" %> Here are my routes: config/routes.rb: ----------------- SampleApp::Application.routes.draw do get "users/new" #get "pages/home" #get "pages/contact" #get "pages/about" #get "pages/help" match ''/signup'', :to => ''users#new'' match ''/about'', :to => ''pages#about'' match ''/contact'', :to => ''pages#contact'' match ''/help'', :to => ''pages#help'' root :to => ''pages#home'' end Here are my controllers: users_controller.rb: ------------------- class UsersController < ApplicationController def new @title = "Sign up" end end pages_controller.rb: ------------------ class PagesController < ApplicationController def home @title = "Home" end def contact @title = "Contact" end def about @title = "About" end def help @title = "Help" end end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Cross posted to: http://stackoverflow.com/questions/6701223/rail3-tutorial-testing-click-link-error -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 July 2011 22:59, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Here is the error I am getting: > > > .....F > > Failures: > 1) LayoutLinks should have the right links on the layout > Failure/Error: click_link "Sign up" > Could not find link with text or title or id "Sign up" > # ./spec/requests/layout_links_spec.rb:37:in `block (2 levels) in > <top (required)>''I presume that you have looked at the html generated for that page (View > Page Source or similar in your browser) to see whether it is the html that is at fault or the test. If it is the html then what html is generated for that link and what do you expect it to be to pass the test? If you think the html is correct and the test should pass then show us the html for the link. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, Thanks for the response. When I manually click on the ''Sign up'' link on the Home page, it successfully displays the following page (which is what I want): app/views/users/new.html.erb ---------------------------- <h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p> And if I click on View Source for the Home page, the ''Sign up'' link is there (not to be confused with the "Sign in" link): <!DOCTYPE html> <html> <head> <title>My website | Home</title> <meta name="csrf-param" content="authenticity_token"/> <meta name="csrf-token" content="i/PD5uKjp87ArBPcr51a82KeW/5peacAJ6M908f3sP8="/> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link href="/stylesheets/blueprint/screen.css?1310454155" media="screen" rel="stylesheet" type="text/css" /> <link href="/stylesheets/blueprint/print.css?1310454155" media="print" rel="stylesheet" type="text/css" /> <!--[if lt IE 8]> <link href="/stylesheets/blueprint/ie.css?1310454155" media="screen" rel="stylesheet" type="text/css" /> <![endif]--> <link href="/stylesheets/custom.css?1310632912" media="screen" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <header> <a href="/"><img alt="Autumn" class="round" height="140" src="/images/autumn.jpg?1310626333" width="300" /></a> <nav class="round"> <ul> <li><a href="/">Home</a></li> <li><a href="/help">Help</a></li> <li><a href="#">Sign in</a></li> </ul> </nav> </header> <section class="round"> <h1>Me</h1> <p>Hi, this is my website.</p> <a href="/signup" class="signup_button round">Sign up</a> </section> <footer> <nav class="round"> <ul> <li><a href="/about">About</a></li> <li><a href="/contact">Contact</a></li> <li><a href="http://news.railstutorial.org/">News</a></li> </ul> </nav> </footer> </div> </body> </html> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 15, 8:44 am, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > Thanks for the response. When I manually click on the ''Sign up'' link on > the Home page, it successfully displays the following page (which is > what I want): > > app/views/users/new.html.erb > ---------------------------- > <h1>Users#new</h1> > <p>Find me in app/views/users/new.html.erb</p> > > And if I click on View Source for the Home page, the ''Sign up'' link is > there (not to be confused with the "Sign in" link): >If you look at your spec, the line above you''ve gone to the help page, and it''s on that page that a sign up link is being looked for. It''s as if you, in a real browser, was going to the home page and (without opening links in new tabs etc) clicked on links in the order specified, waiting for the page to load after each click Fred> <!DOCTYPE html> > <html> > <head> > <title>My website | Home</title> > <meta name="csrf-param" content="authenticity_token"/> > <meta name="csrf-token" > content="i/PD5uKjp87ArBPcr51a82KeW/5peacAJ6M908f3sP8="/> > <!--[if lt IE 9]> > <script > src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> > <![endif]--> > > <link href="/stylesheets/blueprint/screen.css?1310454155" > media="screen" rel="stylesheet" type="text/css" /> > <link href="/stylesheets/blueprint/print.css?1310454155" > media="print" rel="stylesheet" type="text/css" /> > > <!--[if lt IE 8]> > <link href="/stylesheets/blueprint/ie.css?1310454155" > media="screen" rel="stylesheet" type="text/css" /> > <![endif]--> > > <link href="/stylesheets/custom.css?1310632912" media="screen" > rel="stylesheet" type="text/css" /> > > </head> > > <body> > > <div class="container"> > > <header> > <a href="/"><img alt="Autumn" class="round" height="140" > src="/images/autumn.jpg?1310626333" width="300" /></a> > > <nav class="round"> > <ul> > <li><a href="/">Home</a></li> > <li><a href="/help">Help</a></li> > <li><a href="#">Sign in</a></li> > </ul> > </nav> > > </header> > > <section class="round"> > <h1>Me</h1> > <p>Hi, this is my website.</p> > > <a href="/signup" class="signup_button round">Sign up</a> > > </section> > > <footer> > <nav class="round"> > <ul> > <li><a href="/about">About</a></li> > <li><a href="/contact">Contact</a></li> > <li><a href="http://news.railstutorial.org/">News</a></li> > </ul> > </nav> > </footer> > > </div> > > </body> > </html> > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Fred. After spending hours creating a duplicate app, I happened to cut and paste the ''Sign up'' click_link in a different order, and the tests passed. After pasting the ''Sign up'' click_link in several different places and examining the results, I came up with the explanation you posted. I was about to give up! I would have seen your explanation eventually, so thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.