मैं पूरी तरह से यहां फंस गया हूं, और उम्मीद करता हूं कि कोई मुझे सही दिशा में इंगित कर सकता है। मैं अपने webroutes का परीक्षण करने के लिए rspec का उपयोग करने की कोशिश कर रहा हूँ। मेरी कल्पना फ़ाइल नामित होने के साथNoMethodError: rspec चलाते समय अपरिभाषित विधि 'प्राप्त करें' और कॉल प्राप्त करें/विज़िट करें
https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
: मैं यहाँ उदाहरण का पालन कल्पना में api_tests_spec.rb/फ़ोल्डर अनुरोध करता है।
इस प्रकारrequire 'spec_helper'
describe "APITests" do
describe "GET /regions" do
it "should return a valid response" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get "/regions.json"
response.status.should be(200)
#print response.body
end
end
end
दुर्भाग्य से मैं हो रही है विफलता संदेश है::
1) APITests प्राप्त/क्षेत्रों एक वैध प्रतिक्रिया विफलता/त्रुटि लौटानी चाहिए:
फ़ाइल प्रकार है मिल " /regions.json " NoMethodError: अपरिभाषित विधि` # # के लिए मिलता है './api_tests_spec.rb:7
किसी को भी क्यों में किसी भी जानकारी है विधि नहीं मिल सकती है? मैंने जो कुछ भी पढ़ा है, वह यह सुझाव देता है कि कुछ ठीक से शामिल नहीं हो रहा है, लेकिन समाधान हमेशा फाइल को अनुरोध फ़ोल्डर में ले जाने के लिए प्रतीत होता है (जहां मेरा पहले से है)। अग्रिम में धन्यवाद!
spec_helper.rb फ़ाइल इस तरह दिखता है:
# 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 'rspec/autorun'
# 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
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# 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
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
आप परीक्षण कैसे चला रहे हैं? आपके spec_helper में क्या है? – Gazler
बंडल exec rspec api_tests_spec.rb, spec_helper एक संपादन के रूप में जोड़ा गया – akhalsa