我该如何从黄瓜中调用模型

时间:2012-08-27 09:16:18

标签: ruby-on-rails rspec cucumber

  • 我怎样才能在黄瓜试验中使用哪种情况?
  • 我需要测试重置密码功能。

以下是我的代码

  Given /^I have successfully requested a password reset "(.*?)" and enter "(.*?)"$/ do |url, username|
    visit url
    fill_in "username", :with => username
    click_button "Request"
    @current_user = User.find_by_username!(username)
    click link("http://localhost:3000/edit/"#{@current_user.token}"/password")
  end

但我收到了错误

uninitialized constant User (NameError)

支持/ env.rb

require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'rspec'

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :firefox)
end


Capybara.run_server = false
Capybara.default_driver = :selenium
Capybara.default_selector = :css

module Helpers
  def without_resynchronize
    page.driver.options[:resynchronize] = false
    yield
    page.driver.options[:resynchronize] = true
  end
end

World(Capybara::DSL, Helpers)

0 个答案:

没有答案