2

我已经格式化了我的计算机,并且在重新安装 Rails 时将我的数据库更改为 postgres,现在之前通过的一些测试失败了,例如以下代码:

describe "Tickets" do
  subject { page }

  describe "when creating a new ticket successfully" do
    before do
      login_as_user
      visit new_ticket_path
      fill_in "Subject", with: "Test ticket"
      fill_in "Description", with: "This is a test ticket"
      select 'Billing', from: "ticket[category]" 
      click_button "Submit Ticket"
      TicketNotifier.drain
      Sidekiq::Extensions::DelayedMailer.drain
    end

    specify { last_email.to.should include("my.email@gmail.com") }
    it { should have_selector('title', text: "Ticket #1") }
    it { should have_content("ticket has been submitted successfully") }
  end
end

返回以下错误:

  10) Tickets when creating a new ticket successfully 
     Failure/Error: TicketNotifier.drain
     ActiveRecord::RecordNotFound:
       Couldn't find Ticket with id=366
     # ./app/workers/ticket_notifier.rb:5:in `perform'
     # ./spec/requests/blas_spec.rb:14:in `block (3 levels) in <top (required)>'

   # same error repeated a few times...

或者:

context "should not be able to edit other user's website" do
  before { visit edit_rental_path(1) }

  it { should have_selector('title', text: "Your Websites") }
  it { should have_selector(notice, text: "You do not have access to this domain.") }
end

抛出以下几个:

  2) Websites create a user with 2 websites log user out log in second user should not be able to edit other user's website 
     Failure/Error: before { visit edit_website_path(1) }
     ActiveRecord::RecordNotFound:
       Couldn't find Website with id=1
     # ./app/controllers/websites_controller.rb:116:in `correct_user'
     # ./spec/requests/websites_spec.rb:187:in `block (6 levels) in <top (required)>'

那么,它是否为每个it { should ... }子句创建一个新对象?
即使我尝试以下类似的操作,它也无法通过 id 找到:

@site = Website.where(link: "http://google.com").first
visit website_path(@site)

造成这些问题的原因是什么?

更新

我已经按照 depa 的建议清空了我的 gemset,现在我发布的第一个测试没有出错,即使我指定it { should have_selector('title', text: "Ticket #1") }. 来自票证的#1ID,因此出于某种原因,它正在像以前一样进行那些测试,但我仍然会在其他人身上遇到错误,除非我将它们更改为:

before do
   # create the ticket
   @ticket = Ticket.where(...).first
end

it { should have_selector('h2', text: "Ticket ##{@ticket.id}") }

而以前如果我只是离开它,因为Ticket #1测试会通过。作为测试数据库的工作方式postgres和工作方式不同吗?sqlite

4

1 回答 1

1

我会尝试重置您的 gem 环境,从使用 RVM开始gem pristine rspec-rails,一直到现在gem pristine capybara为止。rvm gemset empty

于 2013-04-20T16:29:58.427 回答