Я пытаюсь проверить расширение веселья.Некоторые из тестов являются функциональными.В этих тестах в качестве драйвера javascript используется selenium-webdriver.Вот мой gemspec для расширения.
spree_extension.gemspec
# Runtime
s.add_dependency 'spree_core', '>= 3.2', '< 3.6'
s.add_dependency 'spree_sample', '>= 3.2', '< 3.6'
# Development
s.add_development_dependency 'appraisal'
s.add_development_dependency 'shoulda-matchers', '~> 3.1.1'
s.add_development_dependency 'factory_bot', '~> 4.8.2'
s.add_development_dependency 'coffee-rails', '~> 4.2.1'
s.add_development_dependency 'database_cleaner', '~> 1.5.3'
s.add_development_dependency 'sqlite3', '~> 1.3.11'
s.add_development_dependency 'capybara', '~> 2.7.1'
s.add_development_dependency 'selenium-webdriver', '~> 2.53.0'
s.add_development_dependency 'launchy', '~> 2.4.3'
s.add_development_dependency 'rspec-rails', '~> 3.7'
spec_helper.rb
# Configure Rails Environment
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'database_cleaner'
require 'factory_bot'
FactoryBot.find_definitions
require 'ffaker'
require 'paperclip/matchers'
require 'shoulda/matchers'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
# Requires factories defined in spree_core
require 'spree/testing_support/factories'
require 'spree/testing_support/controller_requests'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/capybara_ext'
require 'spree/testing_support/url_helpers'
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.include Paperclip::Shoulda::Matchers
# == URL Helpers
#
# Allows access to Spree's routes in specs:
#
# visit spree.admin_path
# current_path.should eql(spree.products_path)
config.include Spree::TestingSupport::UrlHelpers
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :feature
config.include Spree::TestingSupport::ControllerRequests, type: :controller
# == 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
config.mock_with :rspec
config.color = true
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = File.join( File.dirname(__FILE__), 'spec/fixtures')
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
# to cleanup after each test instead. Without transactional fixtures set to false the records created
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
config.use_transactional_fixtures = false
config.before :each do |example|
if example.metadata[:js]
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
config.fail_fast = ENV['FAIL_FAST'] || false
# rspec-rails 3 will no longer automatically infer an example group's spec type
# from the file location. You can explicitly opt-in to the feature using this
# config option.
# To explicitly tag specs without using automatic inference, set the `:type`
# metadata manually:
#
# describe ThingsController, :type => :controller do
# # Equivalent to being in spec/controllers
# end
config.infer_spec_type_from_file_location!
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
# Or, choose the following (which implies all of the above):
with.library :rails
end
end
Я использую Firefox v45.0.Проблема заключается в том, что хотя окно Firefox открывается и тесты запускаются, но тесты функций, которые взаимодействуют с javascript (определенным в расширении), не выполняются.
В качестве примера приведен один сценарий:
scenario "expect to have a disabled add to cart button" do
visit spree.product_path(product)
within "div.add-to-cart" do
expect(page).to have_css('button#add-to-cart-button')
expect(page.find('button#add-to-cart-button').disabled?).to be_truthy # <= This test here is failing
end
end
Я отключаю кнопку в javascript, который определен в этом расширении, но тест не пройден, потому что я думаю, что мои тесты этого не видят.
Требуется ли селену больше настроек для javascript?