0

我正在编写功能规范以确保我的应用程序的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
4

1 回答 1

0

我的解决方案是删除 spec expect(page).to have_content('Task Created')。由于这是一条 JS toastr 消息,我很难将其隔离,最后我决定测试它对应用程序的整体功能并不重要。我还必须删除Due on,因为这会过去一半时间而另一半失败,即使它会 a)在 bot 浏览器上输入,并且 b)在输入后出现在 bot 页面上。因为我能够进入它,所以我认为测试它的存在不是必需的。

在调试时,我看到了Jonas Nicklas对清理我的规范很有帮助的这篇文章。

最后,我最终离开sleep了我的规范,实际上将它增加到了sleep(10),这增加了规范通过的可能性。

于 2013-04-21T12:42:04.643 回答