करता रूबी 2 के साथ एक रेल 3.2.14 ऐप्लिकेशन में, और capybara निम्नलिखित सुविधा कल्पना एक विफलता उत्पन्न कर रहा है 2.1.0:Capybara/RSpec 'have_css' मेल खाने वाला काम नहीं कर रहा लेकिन has_css rspec-रेल 2.14.0 का उपयोग कर
require 'spec_helper'
feature 'View the homepage' do
scenario 'user sees relevant page title' do
visit root_path
expect(page).to have_css('title', text: "Todo")
end
end
विफलता संदेश है:
1) View the homepage user sees relevant page title
Failure/Error: expect(page).to have_css('title', text: "Todo")
Capybara::ExpectationNotMet:
expected to find css "title" with text "Todo" but there were no matches. Also
found "", which matched the selector but not all filters.
शीर्षक तत्व और सही पाठ गाया पेज
पर हैंलेकिन जब मैं सुविधा कल्पना में इस लाइन बदलने के लिए:
expect(page).to have_css('title', text: "Todo")
इस के लिए
:
page.has_css?('title', text: "Todo")
तो परीक्षण से गुजरता है। [संपादित करें - लेकिन @JustinKo से नीचे प्रतिक्रिया देखते हैं कि इस परीक्षण के लिए एक अच्छा परीक्षण यह हमेशा पारित करेंगे के रूप में नहीं है] मैं काम करने के लिए have_css(...)
प्रपत्र कैसे मिलता है
? क्या यह एक विन्यास मुद्दा है?
यहाँ मेरी Gemfile
के प्रासंगिक हिस्सा है:
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
end
और मेरे spec/spec_helper.rb
इस तरह की स्थापना की है:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
# out of the box rspec config code ommitted
config.include Capybara::DSL
end
किसी को भी पता है कि मैं गलत क्या कर रहा हो सकता है?
आगे जाना है और इस पोस्ट, विशेष रूप से capybara हिस्सा http://nofail.de/2013/10/debugging कृपया पढ़ें:
हालांकि, यह
have_title
विधि का उपयोग आसान होगा -रेल्स-अनुप्रयोग-इन-डेवलपमेंट/ – phoetयदि आप केवल 'पृष्ठ.has_css? (' शीर्षक ', टेक्स्ट: "टोडो") करते हैं, तो परीक्षण हमेशा पास होगा। 'has_css? 'बस सच या गलत लौटाता है, जो परीक्षण में विफल होने के लिए पर्याप्त नहीं है। यदि आप इसे आउटपुट करते हैं, तो आप देखेंगे कि यह गलत है। क्या आप वाकई टेक्स्ट के साथ शीर्षक तत्व हैं? –
@ जस्टिनको न्यूबी त्रुटि को इंगित करने के लिए धन्यवाद। हां, शीर्षक उचित टेक्स्ट के साथ दिख रहा है - ब्राउज़र में चेक किया गया। –