-1

我正在为现有应用程序编写一些集成测试用例。如果只有一个“it”块,我的测试工作正常。但是,如果我添加多个“it”块,则会引发错误。以下是我的有效代码:

require 'spec_helper'
describe 'Group' do
  before do
    visit 'http://groups.caremonkey.com/users/sign_in'
    fill_in "Email", :with => "email@example.com"
    fill_in "Password", :with => "password"
    click_button "Login"
    page.should have_link('Account')
  end
  it 'Should check all the links and functionality of groups' do
    #add new subgroup with valid data should save a new group
    find("#group-squares").click_link("Add")
    fill_in "Group Name", :with => "Melbourne futsal"
    click_on("Save")
    page.should_not have_content("can't be blank")
    page.execute_script("parent.$.fancybox.close();")
    page.should have_link('Account')

    #test edit group: should be able to update group info provided valid data are given
    first(".actual img").click
    page.should have_content("Group")
    page.should have_link("Cancel")
    fill_in "Group name", :with => "Futsal club"
    page.execute_script("$('#sub-group-color-options').find('.color23').click()")
    click_button "Save"
    click_on("Cancel")
    page.should have_link('Account')
  end
end

当我将所有“ it ”块放在一个“it”块中时,它工作得非常好。但是当我将它们分成不同的“它”块时,它就停止工作了。例如,如果我将这个(“测试编辑组:应该能够更新组信息,提供有效数据”)测试用例分成单独的“it”块,如下所示

 require 'spec_helper'
 describe 'Group' do
   before do
     visit 'http://groups.caremonkey.com/users/sign_in'
     fill_in "Email", :with => "email@example.com"
     fill_in "Password", :with => "password"
     click_button "Login"
     page.should have_link('Account')
   end
   it 'add new subgroup with valid data should save a new group' do
     find("#group-squares").click_link("Add")
     fill_in "Group Name", :with => "Melbourne futsal"
     click_on("Save")
     page.should_not have_content("can't be blank")
     page.execute_script("parent.$.fancybox.close();")
     page.should have_link('Account')
   end

   it 'should be able to update group info provided valid data are given' do
     first(".actual img").click
     page.should have_content("Group")
     page.should have_link("Cancel")
     fill_in "Group name", :with => "Futsal club"
     page.execute_script("$('#sub-group-color-options').find('.color23').click()")
     click_button "Save"
     click_on("Cancel")
     page.should have_link('Account')
   end
 end

然后 rspec 失败,它通过了第一个测试,但是第二个测试失败并抛出以下错误。

Failure/Error: visit 'http://groups.caremonkey.com/users/sign_in'
 ActionController::RoutingError:
   No route matches [GET] "/users/sign_in"

还有一件事,我必须测试远程(url:http ://groups.caremonkey.com/ )中的所有功能。因为,我正在为现有应用程序编写集成测试。此外,在测试我的应用程序的其余功能之前,我需要登录系统。在此先感谢您的帮助。

4

2 回答 2

1

您是否按照 Capybara 文档调用远程服务器?它说你应该有以下内容:

Capybara.current_driver = :selenium # Or anything but rack_test, probably
Capybara.run_server = false # Don't run your app in-process
Capybara.app_host = 'http://groups.caremonkey.com/'

我的猜测是,当您访问该站点一次时,未来的visit呼叫将尝试使用相对路由,然后将其路由到默认服务器。ActionController::RoutingError如果你没有运行某种机架服务器,我想不出你为什么会得到一个。您是否在其他 Rails 应用程序中运行这些测试?

于 2013-11-14T13:33:06.803 回答
0

我猜是这样的:

require 'spec_helper'
describe 'Group' do
  before do
    visit 'http://groups.caremonkey.com/users/sign_in'
    fill_in "Email", :with => "email@example.com"
    fill_in "Password", :with => "password"
    click_button "Login"
    page.should have_link('Account')
    find("#group-squares").click_link("Add")  #apperently both specs are "scoped" to this page
  end

  it 'Should check all the links and functionality of groups' do
    fill_in "Group Name", :with => "Melbourne futsal"
    click_on("Save")
    page.should_not have_content("can't be blank")
    page.execute_script("parent.$.fancybox.close();")
    page.should have_link('Account')
  end

  it "test edit group: should be able to update group info provided valid data are given"
    first(".actual img").click
    page.should have_content("Group")
    page.should have_link("Cancel")
    fill_in "Group name", :with => "Futsal club"
    page.execute_script("$('#sub-group-color-options').find('.color23').click()")
    click_button "Save"
    click_on("Cancel")
    page.should have_link('Account')
  end
end

我的直觉告诉我两个测试都需要遵循这个:find("#group-squares").click_link("Add")所以我将它添加到了之前的块这个测试然而是神秘的,什么是 first(".actual img")?

于 2013-11-08T14:55:41.503 回答