Capybara请求规范DSL和交易固定装置

时间:2011-06-11 21:30:02

标签: testing request rspec2 capybara

在capybara 1.0.0.rc1中有一个新的dsl,与牛排非常相似。我正在尝试在后台/部分之前设置一个夹具,但是当我调试第一个场景/示例并检查数据库时,在后台设置的夹具已经消失。我将use_transaction_fixtures设置为true,但奇怪的是,因为background是以前的别名,所以这很重要。我做错了什么?

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 

1 个答案:

答案 0 :(得分:0)

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