我正在编写功能规范以确保我的应用程序的Add Task
行为正常运行。我已经多次运行相同的规范而根本没有编辑代码,有时一个或两个规范都会失败。
我想知道我是否正在做一些特定的事情使我的规格表现不稳定(这就是开发人员在谈论脆弱规格时的意思吗?我想是这样......)。我添加了注释以澄清代码。任何建议表示赞赏。谢谢。
task_feature_spec_helper
include ApplicationHelper
def click_task
visit order_path(order.id)
click_link("Add Task")
end
def add_valid_task
click_task
within("#add_task") do
select 'foo1@example.com', from: 'Assignee'
fill_in 'Due at', {:with => '15/03/25'}
fill_in_html("task__textarea", {:with => task[:description]})
click_button "Save"
end
end
def add_empty_task
click_task
within("div#add_task") { click_button "Save" }
end
task_feature_spec 需要“spec_helper”
feature 'Create Task' do
let(:order) {create(:order)}
let(:task) {attributes_for(:task)} #using attributes for to prevent extra object
before(:each) {login_user} #initliaztion (user squence only goes up if the user is
#saved.)
scenario 'with valid description' , :js => :true do
add_valid_task
expect(page).to have_content('Task Created') #'Task Created' is a momentary JS notification
sleep 1 #this pause allows elements below to render
within("div#tasks-table") do
expect(page).to have_content('Due on 03/15/25')
expect(page).to have_content('Assigned to foo1@example.com')
expect(page).to have_content('Displayed on Ad Hoc')
end
end
scenario 'with invalid (empty) description' , :js => :true do
add_empty_task
sleep 1
expect(page).to have_content("can't be blank")
end
end