新しい Rails アプリに、足場を備えたユーザー モデルを追加しましたrails g scaffold User name email
失敗している一連のテストを生成しました。それらの1つは次のとおりです。
require 'spec_helper'
describe "users/new" do
before(:each) do
assign(:user, stub_model(User,
:name => "MyString",
:email => "MyString"
).as_new_record)
end
it "renders new user form" do
render
assert_select "form[action=?][method=?]", users_path, "post" do
assert_select "input#user_name[name=?]", "user[name]"
assert_select "input#user_email[name=?]", "user[email]"
end
end
end
私の spec_helper.rb は次のとおりです。
require 'rubygems'
require 'spork'
require 'capybara/rspec'
Spork.prefork do
end
Spork.each_run do
end
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :mocha
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
end
しかし、私はエラーが発生しています:
2) users/new renders new user form
Failure/Error: assign(:user, stub_model(User, NoMethodError:
undefined method `stub' for #<User:0x57f0558>
# ./spec/views/users/new.html.haml_spec.rb:5:in `block (2 levels) in <top (
required)>'
どうしたの?