我正在将一个rails 3.2
应用更新为rails 4.2.10
,我已经完成了几乎所有工作,单元测试和集成测试都通过了。
我在功能测试中遇到了一些问题,正在使用capybara 3.3.0
和poltergeist 1.18.1
,这使我在visit '/'
上出现了错误
我在Stack上查看了很多有关试图分配给只读属性的问题,但这些问题都不适用于我的情况,
这是我精简的规格文件
require 'vcr'
Capybara.default_max_wait_time = 10
feature "Create something" do
include SpecHelpers
include Acceptance
before do
setup_database
end
after do
teardown_database
end
scenario "Creating a Consignment", :js => true do
puts "Running with #{Capybara.current_driver}"
VCR.use_cassette('cassette_name.yml') do
page.driver.resize(1000,2200) unless Capybara.current_driver == :selenium
visit '/'
expect(page).to have_content 'EMAIL'
expect(page).to have_content 'PASSWORD'
end
end
end
这是我精简的规范帮助文件
ENV["RAILS_ENV"] ||= 'test'
require_relative '../config/environment.rb'
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/poltergeist'
require 'shoulda/matchers'
require 'redis'
require 'redis-namespace'
require 'resque'
require 'mock_redis'
require 'bcrypt'
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
# rspec
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
RSpec.configure do |config|
config.deprecation_stream = 'log/deprecations.log'
end
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, :type => :controller
end
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
BCrypt::Engine.cost = 1
if (ENV['DEBUG_CAP'])
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
else
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: true})
end
Capybara.javascript_driver = :poltergeist
end
Capybara.server_port = 31337
Capybara.server = :webrick
module SpecHelpers
def setup_database
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
end
def teardown_database
DatabaseCleaner.clean
end
end
module Acceptance
VCR.configure do |c|
require 'webmock'
c.hook_into :webmock
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.allow_http_connections_when_no_cassette = true
c.default_cassette_options = {:record => :new_episodes}
c.ignore_request do |request|
URI(request.uri).port == Capybara.server_port || request.uri=~/shutdown/ || request.uri=~/session/
end
end
def wait_until(timeout = Capybara.default_max_wait_time)
require "timeout"
begin
Timeout.timeout(timeout) do
sleep(0.3) until value = yield
value
end
rescue => e
save_screenshot "capybara_#{Time.now.to_i}.png"
puts e.message
puts e.backtrace
raise e
end
end
end
require "rspec/mocks/standalone"
....
这是错误堆栈跟踪
Running with poltergeist
Error: Attempted to assign to readonly property.
r@http://127.0.0.1:31337/lib/bfd57c67.components.js:22:3139
r@http://127.0.0.1:31337/lib/bfd57c67.components.js:5:3551
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:19730
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12707
s@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:20964
g@http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12573
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:16265
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:22205
c@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
c@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4884
$digest@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:7801
$apply@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:9410
http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26430
a@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26340
Z@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26051
http://127.0.0.1:31337/lib/bfd57c67.components.js:7:28112
d@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:18351
fireWith@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:19152
ready@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:13970
wt@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:11347
Error: Attempted to assign to readonly property.
r@http://127.0.0.1:31337/lib/bfd57c67.components.js:22:3139
r@http://127.0.0.1:31337/lib/bfd57c67.components.js:5:3551
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:19730
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12707
s@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:20964
g@http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12573
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:16265
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:22205
c@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
c@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4884
$digest@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:7801
$apply@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:9410
http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26430
a@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26340
Z@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26051
http://127.0.0.1:31337/lib/bfd57c67.components.js:7:28112
d@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:18351
fireWith@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:19152
ready@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:13970
wt@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:11347
Error: Attempted to assign to readonly property.
r@http://127.0.0.1:31337/lib/bfd57c67.components.js:22:3139
r@http://127.0.0.1:31337/lib/bfd57c67.components.js:5:3551
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:19730
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12707
s@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:20964
g@http://127.0.0.1:31337/lib/bfd57c67.components.js:5:12573
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:16265
http://127.0.0.1:31337/lib/bfd57c67.components.js:5:22205
c@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
c@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4206
http://127.0.0.1:31337/lib/bfd57c67.components.js:6:4884
$digest@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:7801
$apply@http://127.0.0.1:31337/lib/bfd57c67.components.js:6:9410
http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26430
a@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26340
Z@http://127.0.0.1:31337/lib/bfd57c67.components.js:4:26051
http://127.0.0.1:31337/lib/bfd57c67.components.js:7:28112
d@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:18351
fireWith@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:19152
ready@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:13970
wt@http://127.0.0.1:31337/lib/bfd57c67.components.js:1:11347
更新1
在进行一些调试后,发现尝试将$render
设置为函数时,会从angularjs-bootstrap-datetimepicker包抛出错误,
var ngModelController = $element.controller('ngModel')
var configuration = createConfiguration()
$scope.screenReader = configuration.screenReader
// Behavior
$scope.changeView = changeView
ngModelController.$render = $render --> in this line