0

我的survey#show观点是在生产和开发中工作,但在测试中失败。

我有:

/app/views/survey/show.html.haml

#{@survey.current_score} out of #{@survey.available_points}

/spec/features/survey_spec.rb

visit competitor_survey_path(@competitor, @survey)
@survey.current_score.should == 1.0 # passes! yay!
@survey.available_points.should == 3.0 # passes! yay!
page.should_have_content "0.0 out of 0.0" #passes! huh???
page.should have_content "1.0 out of 3.0" #fails! huh???

这怎么可能?(正如我所说,它在生产和开发中运行良好。)更重要的是,我该如何解决它?

我已经尝试添加@survey.reload到示例和- @survey.reload if Rails.env.test?视图中。

PS,这是我的/spec/supports/spec_helper.rb

require "rubygems"
require "database_cleaner"
require "pry"
require "plymouth"

ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"
require 'declarative_authorization/maintenance'
include Authorization::TestHelper

require "capybara/rspec"
require "capybara/rails"
require "capybara/dsl"

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.mock_with :rspec
  config.fail_fast = true

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  config.before(:each) { ActionMailer::Base.deliveries.clear }
  config.use_instantiated_fixtures = false 
  config.include(Capybara, :type => :integration)

  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.strategy = :deletion
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.after do
    if example.metadata[:type] == :feature && example.exception.present? && page.current_path.present?
      save_and_open_page
    end
  end

  config.include FactoryGirl::Syntax::Methods

end

def login_as(role)
  @role = Role.create! :name => role
  @virginia = User.create!(
    :username => "Virginia", 
    :password => "password", 
    :password_confirmation => "password", 
    :email => "example@example.com")
  @assignment = Assignment.create! user_id: @virginia.id, role_id: @role.id
  visit login_path
  fill_in "user_session_username", :with => @virginia.username
  fill_in "user_session_password", :with => @virginia.password
  click_on "submit_user_session"
end
4

1 回答 1

0

rspec 默认情况下不呈现视图。如果非常必要,请在文档中检查您应该如何做:https ://www.relishapp.com/rspec/rspec-rails/v/2-2/docs/controller-specs/render-views

于 2013-08-05T13:46:26.060 回答