मेरे लिए, यह काफी अब तक शामिल सबके द्वारा टिप्पणियों का एक संयोजन था।
पहले, मैं यह साधारण परीक्षण के साथ शुरू किया:
it "routes/to the widgets controller" do
get('/').should route_to("mozoo/widget#index")
end
इस के परिणामस्वरूप:
Failures:
1) Mozoo::WidgetController GET widget index routes/to the widgets controller
Failure/Error: get('/').should route_to("mozoo/widget#index")
ActionController::RoutingError:
No route matches {:controller=>"mozoo/widget", :action=>"/"}
# ./spec/controllers/mozoo/widget_controller_spec.rb:9:in `block (3 levels) in <module:Mozoo>'
तो मैं { :get => '/' }
करने के लिए get('/')
से बदल और चीजें महान काम करना शुरू किया। यकीन नहीं है कि क्यों। lib/rspec/rails/matchers/routing_matchers.rb L102-105 के अनुसार, कोई अंतर नहीं है, लेकिन यह मेरे लिए एक फर्क पड़ता है। भले ही, धन्यवाद @ कैमरून-पोप।
it "routes root_path to the widgets controller" do
{ :get => root_path }.should route_to("mozoo/widget#index")
end
और इस त्रुटि हो रही थी:
before(:each) { @routes = Mozoo::Engine.routes }
:
Failures:
1) Mozoo::WidgetController GET widget index routes root_path to the widgets controller
Failure/Error: { :get => '/mozoo' }.should route_to("mozoo/widget#index")
No route matches "/mozoo"
# ./spec/controllers/mozoo/widget_controller_spec.rb:14:in `block (3 levels) in <module:Mozoo>'
तो मैं इस जोड़ा
इसके बाद, मैं एक बहुत सरल और बहुत ही इसी तरह की परीक्षा के रूप में है कि इसके बाद के संस्करण जोड़ा
और एक बेहतर/अलग त्रुटि मिली:
Failures:
1) Mozoo::WidgetController GET widget index routes root_path to the widgets controller
Failure/Error: { :get => root_path }.should route_to("mozoo/widget#index")
The recognized options <{"controller"=>"mozoo/widget", "action"=>"index", "section"=>"mozoo"}> did not match <{"controller"=>"mozoo/widget", "action"=>"index"}>, difference: <{"section"=>"mozoo"}>.
<{"controller"=>"mozoo/widget", "action"=>"index"}> expected but was
<{"controller"=>"mozoo/widget", "action"=>"index", "section"=>"mozoo"}>.
# ./spec/controllers/mozoo/widget_controller_spec.rb:14:in `block (3 levels) in <module:Mozoo>'
वहाँ से, मैं अपने परीक्षण बदल धारा (नाम स्थान मेरी इंजन के अधीन है) शामिल करने के लिए:
{ :get => root_path }.should route_to(:controller => "mozoo/widget", :action => "index", :section => "mozoo")
और वाइला, यह पारित कर दिया। धन्यवाद @ स्टीवन-एंडरसन।
यह अगला हिस्सा विषम है। एक विशिष्ट विजेट जो एक नामित मार्ग के लिए widget_path यूआरएल सहायक इस्तेमाल किया के लिए एक और परीक्षण को जोड़ने के बाद:
it "will successfully serve the widget show page" do
visit widget_path(:foobar)
response.should be_success
end
परीक्षण तुरंत साथ मुझ पर ऊपर blowd:
Failures:
1) GET bubble_summary_row widget will have the content section properly scoped
Failure/Error: visit widget_path(:bubble_summary_row)
NoMethodError:
undefined method `widget_path' for #<RSpec::Core::ExampleGroup::Nested_3:0x0000010748f618>
# ./spec/views/mozoo/widgets/show.html.haml_spec.rb:7:in `block (2 levels) in <module:Mozoo>'
तो मैं निम्नलिखित spec_helper config प्रविष्टि जोड़ा :
RSpec.configure do |config|
config.include Testy::Engine.routes.url_helpers
end
और बीएएम! यह गुजर गया। धन्यवाद @ सैम-सोफ। यह अजीब बात यह है कि बाद में इस टिप्पणी को बनाने के दौरान, मैंने उस कॉन्फ़िगरेशन एंट्री को हटा दिया और त्रुटि को वापस पाने के लिए हटा दिया और मैं कॉन्फ़िगरेशन एंट्री को हटाकर त्रुटि को पुन: उत्पन्न करने में असमर्थ था। ओह ठीक है, मैं आगे बढ़ रहा हूँ। उम्मीद है कि यह लंबी हवादार खाता किसी की मदद करता है।
आप मार्ग देख पा रहे हैं जब आप रेक मार्गों को चलाने के? –
क्या आपको index_routing_spec.rb में 'spec_helper' की आवश्यकता है? – squarism
रेक मार्ग रेल इंजन 3.1 इंजन में काम नहीं करते हैं।शायद यह एक बग है लेकिन इसे यहां समझाया गया है: http://stackoverflow.com/questions/7431687/listing-rake-routes-for-a-mountable-rails-3-1-engine –