2015-11-17 9 views
10

मैं एक मणि लिख रहा हूं जो रेल के साथ एकीकृत करता है, और मैं अपने मणि के परीक्षण सूट के अंदर rspec के साथ एक डमी ऐप का परीक्षण करने में सक्षम होना चाहता हूं।एक मणि लिखते समय आप एक डमी रेल ऐप का परीक्षण कैसे करते हैं?

मुद्दा जब मैं परीक्षण ऊपर आता है मेरे डमी रेल एप्लिकेशन के लोड/एक जोड़े मॉड्यूल के माध्यम से rspec spec/integration/rails/load_path_spec.rb

अब तक, इस है अगर मैं क्या है:

# spec/support/rails_app/config/environment.rb 

# Load the Rails application. 
require File.expand_path('../application', __FILE__) 

# Load the gem 
require 'skinny_controllers' 

# Initialize the Rails application. 
Rails.application.initialize! 

मेरे परीक्षण इस तरह दिखता है:

require 'rails_helper' 

describe 'definitions of operations and policies' do 
    it 'loads operations' do 
    is_defined = defined? EventOperations 
    expect(is_defined).to be_truthy 
    end 

    it 'loads policies' do 
    is_defined = defined? EventPolicy 
    expect(is_defined).to be_truthy 
    end 
end 

rails_helper इस तरह दिखता है:

require 'rails/all' 

require 'factory_girl' 
require 'factory_girl_rails' 
require 'rspec/rails' 

require 'support/rails_app/config/environment' 

ActiveRecord::Migration.maintain_test_schema! 

# set up db 
# be sure to update the schema if required by doing 
# - cd spec/rails_app 
# - rake db:migrate 
ActiveRecord::Schema.verbose = false 
load "support/rails_app/db/schema.rb" # use db agnostic schema by default 


require 'support/rails_app/factory_girl' 
# require 'support/rails_app/factories' 
require 'spec_helper' 

और spec_helper इस तरह दिखता है:

require 'rubygems' 
require 'bundler/setup' 

require 'pry-byebug' # binding.pry to debug! 
require 'awesome_print' 

# Coverage 
ENV['CODECLIMATE_REPO_TOKEN'] = '' 
require 'codeclimate-test-reporter' 
CodeClimate::TestReporter.start if ENV['TRAVIS'] 


# This Gem 
require 'skinny_controllers' 

$LOAD_PATH.unshift Dir[File.dirname(__FILE__) + '/support/operations'].first 
$LOAD_PATH.unshift Dir[File.dirname(__FILE__) + '/support/policies'].first 
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file| 
    # skip the dummy app 
    next if file.include?('support/rails_app') 

    require file 
end 

# This file was generated by the `rspec --init` command. Conventionally, all 
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 
# Require this file using `require "spec_helper"` to ensure that it is only 
# loaded once. 
# 
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 
RSpec.configure do |config| 
    config.run_all_when_everything_filtered = true 
    config.filter_run :focus 
    # Run specs in random order to surface order dependencies. If you find an 
    # order dependency and want to debug it, you can fix the order by providing 
    # the seed, which is printed after each run. 
    #  --seed 1234 
    config.order = 'random' 
end 

यह की तरह लगता है, समय के आधे, जब मैं rspec चलाने के लिए, परीक्षण के सभी गुजरती हैं।

अगर कोई उत्सुक है, मेरे भंडार यहाँ है: https://github.com/NullVoxPopuli/skinny_controllers

उत्तर

10

यहाँ कैसे मैं एक रेल एप्लिकेशन here is the gem where I have a dummy rails app

परीक्षण आप अपने रेल एप्लिकेशन परीक्षण करना चाहते हैं जो कुछ भी कल्पना फाइलों में समाप्त हो गया है, तो आप करेंगे , एक नई फ़ाइल है, जो मैं rails_helper.rb

require 'rails/all' 

require 'factory_girl' 
require 'factory_girl_rails' 
require 'rspec/rails' 

require 'support/rails_app/config/environment' 

ActiveRecord::Migration.maintain_test_schema! 

# set up db 
# be sure to update the schema if required by doing 
# - cd spec/support/rails_app 
# - rake db:migrate 
ActiveRecord::Schema.verbose = false 
load 'support/rails_app/db/schema.rb' # db agnostic 

require 'support/rails_app/factory_girl' 
require 'spec_helper' 

और फिर spec/support फ़ोल्डर में कहा जाता है की आवश्यकता होती है एप्लिकेशन आपकी रेल उत्पन्न करना चाहते हैं। मेरा है: 'spec/support/rails_app'। यहां, डिफ़ॉल्ट मचान उत्पन्न होने की तुलना में रेल ऐप को बहुत पतला कर दिया जा सकता है।

मैं ऐप में बदलाव करने के लिए, config/environment.rb

# Load the Rails application. 
require File.expand_path('../application', __FILE__) 

# gem should be required here 
require 'skinny_controllers' 

# Initialize the Rails application. 
Rails.application.initialize! 

में और database.yml के लिए किया,

default: &default 
    adapter: sqlite3 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    database: db/development.sqlite3 

test: 
    <<: *default 
    database: db/test.sqlite3 

db सेटिंग शायद इन-स्मृति का उपयोग बदला जा सकता है sqlite, अगर एक वांछित है।

उम्मीद है कि यह है। अगर मुझे कुछ याद आया, तो मैं इस जवाब को अपडेट कर दूंगा।

संबंधित मुद्दे