【发布时间】:2014-04-22 00:30:21
【问题描述】:
我有一个非常简单的应用程序,我正在尝试使用 rspec 进行测试。我很难确定是我的配置有问题,还是代码有问题。 /people/index.html.erb 的第一行是<h1>Totally Awesome Page</h1>。
错误:
expected to find text "Totally Awesome Page" in "Index"
./spec/features/people_spec.rb:19:in `block (3 levels) in <class:PeopleSpec>'
测试宝石:
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'capybara'
gem 'factory_girl_rails'
end
spec/features/people_spec.rb:
require 'spec_helper'
class PeopleSpec < ActionDispatch::IntegrationTest
describe "People" do
describe "Index" do
before { visit '/people'}
it { should have_content('Totally Awesome Page')}
end
end
end
spec/spec_helper:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'minitest/autorun'
require 'capybara/rails'
require 'capybara/rspec'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.include Capybara::DSL
end
路线:
people_path GET /people(.:format) people#index
POST /people(.:format) people#create
new_person_path GET /people/new(.:format) people#new
edit_person_pathGET /people/:id/edit(.:format) people#edit
person_path GET /people/:id(.:format) people#show
PATCH /people/:id(.:format) people#update
PUT /people/:id(.:format) people#update
DELETE /people/:id(.:format) people#destroy
【问题讨论】:
-
检查
launchygem。这种规格真是太棒了。 -
为该路径显示
rake routes。
标签: ruby-on-rails rspec capybara