के साथ एक रेल 3 इंजन का परीक्षण कैसे करें मैं एक रेल इंजन विकसित कर रहा हूं जो डेविस जेम पर निर्भर करता है। मेरा इंजन भी एक मणि है और मुझे उस चीज़ के लिए परीक्षण लिखने की जरूरत है। इस के लिए मैं कैसे एक रत्न के अंदर से एक इंजन का परीक्षण करने की रीडिंग के बहुत सारे किया था और मैं निम्नलिखित सेटअप करने के लिए आया था:डेविस और आरएसपीसी
my_engine
+- app # my engine stuff
+- config # my engine stuff
+- Gemfile
+- lib # my engine stuff
+- publiC# my engine stuff
+- spec
+- controllers # controller tests
+- models # model tests
+- dummy # a dummy application that is using the 'my_engine/Gemfile'
+- spec_helper.rb # the spec helper that boots the dummy app
इससे पहले कि मैं वसीयत मणि शामिल है, मैं परीक्षण लिखने और उन्हें
साथ चला सकते हैंrake spec
अब मैं वसीयत मणि और इस
class Manager::User < ActiveRecord::Base
devise :database_authenticatable, :registerable, # ...
end
की तरह एक उपयोगकर्ता मॉडल है और मेरे परीक्षण उपयोगकर्ता वर्ग और वसीयत कॉल की ओर इशारा करते असफल।
`method_missing': undefined method `devise'
तो अब मैं त्रुटि की जांच और बूट करने के लिए कैसे डमी आवेदन चिंतन करना और मेरे इंजन के साथ एक साथ पता लगाने के लिए प्रयास करें। कल्पना सहायक इस
# my_engine/spec/spec_helper.rb#
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../dummy/config/environment.rb", __FILE__) # boots the dummy app and fails
# more rspec stuff gies here
तरह application.rb
# my_engine/spec/dummy/config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env) if defined?(Bundler)
# Dummy::Application definition follows here (the common stuff)
boot.rb
# my_engine/spec/dummy/config/boot.rb
require 'rubygems'
# Loads the gemfile from 'my_engine/Gemfile'
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end if File.exist?(gemfile)
gemfile लग रहा है evnironment.rb
# my_engine/spec/dummy/config/environment.rb
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Dummy::Application.initialize!
# my_engine/Gemfile
source :gemcutter
gem 'rails', '3.0.3'
gem 'rake'
gem 'devise', '>=1.2.rc'
gem 'declarative_authorization', '0.5.2'
group :test do
gem "cucumber"
gem "cucumber-rails"
gem "database_cleaner"
gem "capybara", ">= 0.4.0"
gem "capybara-envjs"
gem "culerity"
gem "webrat"
gem "rspec-rails", ">= 2.4.0"
gem "jeweler"
end
मैं भी करने की कोशिश की इस
gem "my_engine", :path => "./"
Gemfile और जवाहरात सभी लोड किए गए हैं की तरह मेरे इंजन की आवश्यकता होती है (Bundler.setup के माध्यम से चलाता है और वसीयत निरंतर उपलब्ध है)।
अब मैंने एक बाहरी एप्लिकेशन बनाया है जो my_engine मणि का उपयोग करता है। जब मैं अपने इंजन से परीक्षण कॉपी करता हूं और उन्हें चलाता हूं, तो वे सभी पास हो जाते हैं।
क्या मुझे कुछ भी याद आ रही है? शायद इंजन के लिए परीक्षण लिखने का एक बेहतर तरीका है?
अच्छा :) मैं इसे अपने रत्नों के लिए एक गाइड के रूप में उपयोग करूंगा :) – m4risU
मैं ऐप के लिए एक जेमफाइल स्थापित करने का दृष्टिकोण ले रहा हूं जो इंजन के gemspec से अलग है 'gemfile = file.expand_path (' ../../../../Gemfile ', __FILE __) 'और शेष नए जेनरेट किए गए ऐप की सामान्य सामग्री के साथ बदलकर बदलना। –