【发布时间】:2013-08-24 21:05:05
【问题描述】:
嘿,我是 BDD 测试的新手,特别是测试。我正在使用 rspec、factory_girl_rails、selenium 和 capybara gem。我想测试编辑数据并像这样保存它:
it "edit consultant" do
# c = FactoryGirl.create(:consultant)
c = Consultant.create(
orgorcom: "xyz",
year_id: 8,
bidang: "IT & Networking",
project: "E-Sw",
professional_fee: "1000000",
role: "Database Architect",
user_id: 19,
nopkj: "075899 "
)
visit "/consultants?year=#{Time.now.year}"
string = "#consultant#{c.id}"
page.find(string).click_link('Edit')
fill_in "Organization / Company" , :with => c.orgorcom + "aaa"
fill_in "Field", :with => c.bidang + "aaa"
fill_in "Project" , :with => c.project + "aaa"
fill_in "Role", :with => c.role + "aaa"
fill_in "Professional fee", :with => c.professional_fee + 111
click_button "Save"
expect(page).to have_content "Data updated."
sleep 10
# c.destroy
# find('a[href="/consultants/6144/edit?year=2013"]').click
end
但我创建的数据没有出现,我收到了这条消息
1) the consultation edit consultant
Failure/Error: page.find(string).click_link('Edit')
Capybara::ElementNotFound:
Unable to find css "#consultant6157"
当我尝试点击下面的现有数据时,它通过了。
page.find("#consultant6144").click_link('Edit')
我能够打印出顾问 id,但在测试结束之前记录仍然神秘地没有出现(数据库将回滚)。
【问题讨论】:
-
我看不出这与 FactoryGirl 有什么关系。您注释掉了调用 FactoryGirl 的行。您只是使用
.create创建一个对象——这是一个 Rails 方法,而不是 FactoryGirl 方法。 -
您是否为当年的顾问分页超过一页,以至于最近添加的顾问不在页面上?
-
@PeterAlfvin 不,我没有分页,所有数据都是可见的。
-
@depa, (0.2ms) RELEASE SAVEPOINT active_record_1 (0.6ms) ROLLBACK,这是 FactoryGirl 的功能还是什么?
-
这与 FactoryGirl 完全无关。那是你的测试框架为你处理你的测试数据库。
标签: ruby-on-rails rspec capybara factory-bot