mercredi 29 novembre 2017

Cucumber test can't render full page, only header

I'm fairly new to Cucumber/BDD and I'm kind of stumped. I'm trying to do a simple test of page contents but it seems that my test suite can only "find" the page header.

For example:

Scenario: User sees the menu page
  Given a menu exists
  When I visit the menu
  Then I should see "menu" page title
  And I should see "tuna poke" item name

Step definitions:

Given("a menu exists") do
  user = User.create!(email: "test@valid.email", password: "hello")
  restaurant = Restaurant.create!(name: "eleven tables", user_id: user.id)
  menu = Menu.create!(restaurant_id: restaurant.id)
  category = Category.create!(name: "appetizer")
  menu_item = MenuItem.create!(name: "tuna poke", description: "it's light", price: 9, category: category, menu: menu)
end

When("I visit the menu") do
  visit restaurant_menu_path
end

Then("I should see {string} page title") do |string|
  expect(page).to have_title "#{string}"
end

And("I should see {string} item name") do |item_name|
  expect(page).to have_content "#{item_name}"
end

Gives me the result:

Feature: View Menu
  In order see the menu
  I want to view the menu
  I want to see item name
  I want to see item description
  I want to see item price

  Scenario: User sees the menu page        # features/view_menu.feature:8
    Given a menu exists                    # features/step_definitions/view_menu_steps.rb:1
    When I visit the menu                  # features/step_definitions/view_menu_steps.rb:9
    Then I should see "menu" page title    # features/step_definitions/view_menu_steps.rb:13
    And I should see "tuna poke" item name # features/step_definitions/view_menu_steps.rb:17
      expected to find text "tuna poke" in "menu sign in" (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/view_menu_steps.rb:18:in `"I should see {string} item name"'
      features/view_menu.feature:12:in `And I should see "tuna poke" item name'

Failing Scenarios:
cucumber features/view_menu.feature:8 # Scenario: User sees the menu page

1 scenario (1 failed)
4 steps (1 failed, 3 passed)
0m1.180s

The thing I find most peculiar is this part of the error:

expected to find text "tuna poke" in "menu sign in"

Which doesn't make a lot of sense to me. The only time those three words appear together is when you're on the /menu page of my application as a logged-out user in the nav bar. Which is precisely the case here. But I can't figure out why it can't read the contents of the entire page.

Aucun commentaire:

Enregistrer un commentaire