【问题标题】:Rspec not matching titleRspec与标题不匹配
【发布时间】:2012-12-27 00:17:38
【问题描述】:

我有以下规格

describe "user enters 150 into time" do
 before do
   fill_in "workout[total_time]", with: "150"
   click_button "Update Workout"
 end
  it "should be on profile page" do
    save_and_open_page
    page.should have_selector("h1", text: "Profile")
    page.should have_selector("title", text: "Profile")
  end
end

失败并显示以下消息:

Capybara::ExpectationNotMet: expected to find css "title" with text "Profile" but there were no matches. Also found "", which matched the selector but not all filters.

源代码(来自save_and_open_page)包含这个head 部分:

<head>
 <meta content="width=device-width, initial-scale=1.0" name="viewport">
 <title>Profile
 </title>
 <meta content="Composer Delete" name="description">
 <link href="/assets/application.css" media="all" rel="stylesheet" type="text/css">
 <script src="/assets/application.js" type="text/javascript"></script>
</head>

这里是视图:

- content_for :title do
  Profile
%h1 Profile
%table.table.table-striped
  %thead
    %tr
      %th Name
  %tbody
  - current_user.workouts.each do |workout|
    %tr
      %td= link_to workout.name, workout
      %td= link_to "Edit", edit_profile_workout_url(workout)
      %td= link_to "Remove", profile_workout_url(workout), method: :delete, confirm: "Are you sure?"
= link_to "Create New Workout", new_profile_workout_url

content_for 来自layouts/application.html.haml

%title= content_for?(:title) ? yield(:title) : "Composer Delete"

页面标题显示为“个人资料”。

知道为什么这个规范失败了吗?

Rails 3.2.3

Ruby 1.9.3

【问题讨论】:

    标签: ruby-on-rails rspec capybara


    【解决方案1】:

    这是 Capybara 2.0 的错误(或功能:)。尝试使用以前的版本(1.1.2 对我来说很好)。

    https://github.com/jnicklas/capybara/issues/844

    使用 has_title 拉取请求?匹配器:

    https://github.com/jnicklas/capybara/issues/844

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多