我正在测试项目的创建(使用 rspec 集成测试),我想知道为什么测试找不到我刚刚告诉它创建的项目......这是我的代码
1 require 'spec_helper'
2
3 describe "Projects" do
4 describe "create project" do
5
6 before :each do
8 @valid_project = { :name => 'Myproject', :description => 'project description' }
9 end
10
11 it "should create and redirect to a new project" do
12 lambda do
13 visit root_path
14 click_link 'new project'
15 fill_in :name, :with => @valid_project[:name]
16 fill_in :description, :with => @valid_project[:description]
17 click_button 'Create'
18 current_path.should == project_path(Project.find_by_name!(@valid_project[:name]))
19 page.should have_content 'Project has been created'
20
21 #in adition, all these don't work and I don't know why...
22
23 #response.should render_template :new
24 #page.should have_content 'Myproject'
25 #response.should have_selector('h1', :content => 'Myproject')
26
27 end.should change(Project, :count).by(1)
28 end
29 end
30 end
第 18 行返回此错误:
ActiveRecord::RecordNotFound: 找不到名称 = Myproject 的项目
我不明白为什么......在上面代码的评论中还有一些不起作用的测试,我也不知道为什么......谢谢你的帮助。