在 Rails 4.0 的 Windows 上使用 rspec 3.0、ruby 2.0.0p195 运行功能规范时出现此错误。在谷歌上阅读,我发现修复是使用 rpsec 2.0 中的特定版本,但没有超过该版本。我以为我早就解决了这个问题。和其他人一样,我发现当我手动执行该功能的步骤时,一切都按预期工作。没有指示规范的哪一行失败。我应该在哪里查看 Google 以解决此问题?还是我在某个地方搞砸了?
gemfile.lock
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-rails (3.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
在这里失败:_score_form.html.erb
<%= simple_form_for [@site, @inspection, score] do |f| %>
<%= f.input :note %>
<%= f.button :submit, submit_text %>
<% end %>
<a class="close-reveal-modal">×</a>
note_feature_spec.rb
require 'spec_helper'
feature "notes", js: true do
background do
@surveys = ["Loss", "Solutions"]
@manager = FactoryGirl.create(:manager)
@site = FactoryGirl.create(:site)
@user = FactoryGirl.create(:user, site_id: @site.id)
@survey = FactoryGirl.create(:survey, name: "#{@surveys[1]}", user_id: @manager.id)
@item_1 = FactoryGirl.create(:item, name: "item 1", survey_id: @survey.id, category: "Regular", sub_category:
'DEC')
@variance = FactoryGirl.create(:cash_variance)
end
scenario "appear when saved with a score" do
visit root_path
click_link 'Login'
fill_in 'Email', with: @manager.email
fill_in 'Password', with: @manager.password
click_button 'Log in'
click_link ("#{@site.name}" + " #{@site.site_type}")
click_link 'New Inspection'
select("#{@survey.name}")
click_button 'Start inspection'
score = Score.where(inspection_id: Inspection.last.id, item_id: @item_1.id).first
expect(page).to have_content("@item.name")
expect(page).to have_css("note-act#{@score.id}")
end
end
score_controller.rb 的相关部分
class ScoresController < ApplicationController
def update
@site = Site.find(params[:site_id])
@inspection = @site.inspections.find(params[:inspection_id])
@score = @inspection.scores.find(params[:id])
respond_to do |format|
if @score.update_attributes(score_params)
format.html {redirect_to edit_site_inspection_path(@site,@inspection), notice: 'Score was updated'}
format.json {head :no_content}
format.js
else
format.html { render action: 'edit'}
format.json { render json: @score.errors, status: :unprocessable_entity }
end
end
end
错误信息的顶部:
1) notes it appears when saved with a score
Failure/Error: Unable to find matching line from backtrace
ActionView::Template::Error:
undefined method `note' for #<Score:0x8acdb60>
# ./app/views/inspections/_score_form.html.erb:2:in `block in _app_views_inspections__score_form_html_erb__524083191_68481552'
# ./app/views/inspections/_score_form.html.erb:1:in `_app_views_inspections __score_form_html_erb__524083191_68481552'
# ./app/views/inspections/_regular.html.erb:13:in `_app_views_inspections__regular_html_erb__743764807_72723960'
# ./app/views/inspections/_clean_scores.html.erb:17:in `block (3 levels) in _app_views_inspections__clean_scores_html_erb___604997166_72361188'
# ./app/views/inspections/_clean_scores.html.erb:15:in `each'
# ./app/views/inspections/_clean_scores.html.erb:15:in `block (2 levels) in