开发者

selenium test showing email already taken

I am running tests in my Rails 3 application. I use rspec, capybara and Selenium RC.

I have the following test for a form:

require 'spec_helper'
require 'support/database_cleaner.rb'
describe "Greetings" do
  attr_reader :selenium_driver
  alias :page :selenium_driver

  before(:all) do
    selenium_setup
    @selenium_driver.start_new_browser_session
  end

  after(:all) do
    @selenium_driver.close_current_browser_session
    @verification_errors.should == []
  end

  describe "greeting creation" do

 before(:each) do
    @board = Factory(:board)
  end

 describe "success" do
      it "should create and display the greeting" do
           page.open "/boards/#{@board.id}"
           page.click "greeting_link"
           wait_for_ajax
           page.type "greeting_headline", "Hey Have a great day!!!"
           page.type "greeting_content", "I wish you the best birthday ever. Your are a great friend and deserve a great day."
           page.type "user_name", "Example User"
           page.type "user_email", "it@it.com"
           page.click "commit"
           wait_for_ajax
           ("Add greeting").should == page.get_text("greeting_link")
           #("Hey Have a great day!!!").should == page.get_text("css=div.headline.round")
           #page.is_text_present("Hey Have a great day!!!\n\n I wish you the best birthday ever. Your are a great friend and deserve a great day.").should be_true
           #("Hey Have a great day!!!").should == page.get_text("css=div.headline.round")
      end
    end

If I do this text by hand in the browser it works perfectly. However when I run the test it fails because the validation says that the email has already been taken.

I tried rake db:test:prepare. No joy. Same problem.

I have the database_cleaner gem installed in the test environment and have the following in my spec/support/database_cleaner.rb

DatabaseCleaner.strategy = :truncation

RSpec.configure do |config|
  config.use_transactional_fixtures = false
开发者_如何学JAVA  config.before :each do
    DatabaseCleaner.start
  end
  config.after :each do
    DatabaseCleaner.clean
  end
end

I am at a complete loss here as I am a NOOB.

Can anyone point me in the right direction to get this situation fixed?


two obvious possibilities then - one is that the Factory is getting called twice for some reason (in which case putting something like

sequence(:email) {|n| "it@it#{n}.com"}

in your factory should get round the problem. Other possibility is that your factory defines an email address it@it.com - in which case you will get the problem when you try to save the one you create in the test


Here is my config block - config.use_transactional_fixtures = false`

config.before(:suite) do
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
  if example.metadata[:js]
    DatabaseCleaner.strategy = :truncation
  else
    DatabaseCleaner.start
  end
end

config.after(:each) do
  DatabaseCleaner.clean
  if example.metadata[:js]
    DatabaseCleaner.strategy = :transaction
  end
end

end`

I don't really see why that would make a difference, but it might be worth dropping it into yours and giving it a whirl ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜