1
您好我想開始我的第一個回報率的項目,以及遇到問題,一開始時:(Rspec的和水豚未定義的局部變量或方法'頁面」
我有水豚寶石在我的Gemfile:
group :development, :test do
gem 'byebug'
gem 'web-console'
gem 'spring'
gem 'rspec-rails'
gem 'capybara'
gem 'factory_girl_rails'
gem 'database_cleaner'
end
我spec_helper加水豚在我的第一行:
require "capybara/rspec"
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
,並添加它來rails_helper:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'capybara/rspec'
require 'capybara/rails'
但是,當我試圖測試在「投機/控制器/ static_pages_controller_spec.rb正確的標題:
it "have propper title" do
get :home
expect(page).to have_title "Testowy tytuł"
end
我得到了一個錯誤:未定義的局部變量或方法頁
我累了解決這個由我自己,但每個人只說增加要求「水豚/ rspec」
所以我怎麼能在rspec的測試titele? – Kazik 2015-04-04 15:22:06
查看更新。 – fny 2015-04-04 15:23:14
最小的一切都在一個地方。這裏每一塊寶石都有自己的權利。但我想我必須習慣它。 Thnx! – Kazik 2015-04-04 15:31:44