水豚1.0.0.rc1中有一个新的dsl,与牛排非常相似。我试图在后台/之前的部分中设置固定装置,但是当我调试第一个场景/示例并检查数据库时,在后台设置的固定装置不见了。我将use_transactional_fixtures设置为true,但是奇怪的是,考虑到背景是以前的别名,这很重要。我究竟做错了什么?

spec_helper.rb

require 'rubygems'
require 'spork'
require 'capybara/rspec'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require File.expand_path(File.dirname(__FILE__) + "/blueprints")

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    # == Mock Framework
    #
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
    #
    # config.mock_with :mocha
    # config.mock_with :flexmock
    # config.mock_with :rr
    config.mock_with :rspec

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    config.before(:all)    { Sham.reset(:before_all)  }
    config.before(:each)   { Sham.reset(:before_each) }
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.
end


Teacher_creates_event.rb

require 'requests/requests_helper'

feature "Teacher creates event" do
  background do
    Teacher.make(:username => 'testteacher', :password => 'mypassword')
    visit new_user_session_url
    fill_in "Username", :with => 'testteacher'
    fill_in "Password", :with => 'mypassword'
    click_on "Sign in"
  end

  scenario "Teacher creates one-time event" do
    visit studio_calendar_url
    click_on "New Event"
    fill_in "Title", :with => "Test One Time Event"
    fill_in "Description", :with => "An event that occurs once and never repeats..."
    fill_in "Start Date", :with => "2011-07-18"
    fill_in "Start Time", :with => "1:00pm"
    fill_in "End Date", :with => "2011-07-18"
    fill_in "End Time", :with => "3:00pm"
    uncheck "All Day"
    click_on "Create Event"
  end
end

最佳答案

由于某些原因,在我的环境/test.rb中将config.cache_classes设置为true可以使其按预期工作。不知道为什么。

关于testing - capybara 要求规范DSL和交易装置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6318662/

10-13 02:16