user1874182 user1874182 - 1 year ago 65
Ruby Question

Ruby code in my html.erb file not executed during Cucumber test

I'm creating a Ruby on Rails web app and have an index.html.erb file for one of my views that contains the following code:

<div class="container" id="quickTickets">
<% Game.all.each do |game| %>
<%= link_to, game_tickets_path(, :id => "gameid_" %>

The code works correctly when I view it in a browser and displays a header for each game that links to a separate page. However, when I run a Cucumber/Capybara test to simulate clicking on one of the headers, it fails.

The test fails because the block of Ruby code above is not executed when the Cucumber test is run, so the page ends up containing an empty

For example, when I make a call to
print page.html
to examine the HTML my Cucumber test is operating on, it displays the following:

<div class="container" id="quickTickets">

I've spent hours trying to find any documentation or previous bugs like this but haven't found a solution. Any ideas?

Answer Source

Since the container div is in the output the code is being evaluated. Whats likely happening is that you actually don't have Game objects to show. This is either because you haven't created any Game objects in the test, or because you are using a JS capable driver and haven't configured your tests to not use transactions (

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download