升级rspec-rails (2.5.2 -> 3.8.1)
和capybara (2.18.0 -> 3.10.1)
后,两个失败的规范:
不太确定这里发生了什么。看起来期望中的文本被截断了吗?!?
let(:story_attributes) do
{
title: 'Edited title',
description: 'Edited location',
start_year: '2001',
start_month: 'December',
start_day: '5',
end_year: '2001',
end_month: 'October',
end_day: '10',
is_range: true,
cover_image: {
url: 'http://placehold.it/edited.png'
}
}
end
...
within 'section.story-cover' do
expect(page).to have_text 'Edited title'
expect(page).to have_text 'Edited location'
expect(page).to have_text 'December 5th - October 10th, 2001'
end
在第一个失败的示例(如下)中,“编辑的位置”被截断了。
在第二个示例expect(page).to have_text 'Edited title Edited location'
中,仅找到“已编辑标题\ n已编辑位置”。
然后存在一个“ JSON文本必须至少包含两个八位字节”的问题,该问题可能相关也可能不相关,但是在升级rspec-rails和capybara.ds之前通常会通过
有想法吗?
RSpec Failures:
1) Story editing published edit story
Failure/Error: JSON.parse(response.body)
JSON::ParserError:
A JSON text must at least contain two octets!
# ./app/services/converter/image_service.rb:36:in `post_to_filepicker'
# ./app/services/converter/image_service.rb:18:in `convert_format'
# ./app/services/converter/image_service.rb:11:in `block in convert'
# ./app/services/converter/image_service.rb:10:in `each'
# ./app/services/converter/image_service.rb:10:in `convert'
# ./app/models/images/image.rb:5:in `convert'
# ./app/models/images/image.rb:20:in `enqueue_conversion'
# ./app/services/story/updating_service.rb:14:in `update'
# ./app/controllers/stories_controller.rb:58:in `update'
# ------------------
# --- Caused by: ---
# Capybara::ExpectationNotMet:
# expected to find text "Edited location" in "Edited title\nLyla HoegerEditedDecember 5th - October 10th, 2001Download"
# ./spec/features/stories/editing_spec.rb:86:in `block (4 levels) in <top (required)>'
2) Story editing private private story should be read after editing
Failure/Error: JSON.parse(response.body)
JSON::ParserError:
A JSON text must at least contain two octets!
# ./app/services/converter/image_service.rb:36:in `post_to_filepicker'
# ./app/services/converter/image_service.rb:18:in `convert_format'
# ./app/services/converter/image_service.rb:11:in `block in convert'
# ./app/services/converter/image_service.rb:10:in `each'
# ./app/services/converter/image_service.rb:10:in `convert'
# ./app/models/images/image.rb:5:in `convert'
# ./app/models/images/image.rb:20:in `enqueue_conversion'
# ./app/services/story/updating_service.rb:14:in `update'
# ./app/controllers/stories_controller.rb:58:in `update'
# ------------------
# --- Caused by: ---
# Capybara::ExpectationNotMet:
# expected to find text "Edited title Edited location" in "Edited title\nEdited locat"
# ./spec/features/stories/editing_spec.rb:115:in `block (4 levels) in <top (required)>'
答案 0 :(得分:2)
在Capybara 2.x和3.x之间的一大变化是在Capybara 3.x中,文本的返回尽可能接近所显示的内容。这意味着在向用户显示https://github.com/teamcapybara/capybara/blob/master/UPGRADING.md时,换行符现在已包含在返回的文本中。您需要在spec / features / stories / editing_spec.rb:115上将期望的文本更改为“已编辑标题\ n已编辑位置”,或者,如果您不关心换行符,则可以使用:normalize_ws
选项=> expect(page).to have_text("Edited title Edited location", normalize_ws: true)