我正在使用 Rails 3.2.14、Capybara 2.1.0、jquery-fileupload-rails 0.4.1。
如果我尝试围绕文件上传编写测试,但水豚找不到文件输入。规范片段:
describe "Create with all required fields filled" do
before do
choose "Revision File"
select "Publish", from: "file_asset[file_type_ref_id]"
click_button "Next"
script = "$('input[type=file]').show();" # added later
page.driver.browser.execute_script(script)
print page.html # to debug the page
subject { page }
end
describe "Save should create a FileAsset" do
it { should have_selector("span.fileinput-button span") }
it { should have_selector("span.fileinput-button input") }
end
rspec 结果:
Failures:
1) FileAsset Pages New-Create (revision file) Without Authorizations Create with all required fields filled Save should create a FileAsset
Failure/Error: it { should have_selector("span.fileinput-button input") }
expected #has_selector?("span.fileinput-button input") to return true, got false
# ./spec/requests/file_asset_pages_spec.rb:63:in `block (6 levels) in <top (required)>'
Finished in 16.95 seconds
2 examples, 1 failure
即,第一个示例成功运行,但第二个没有,但是 html 页面包含两者(的输出片段print page.html
):
<div class="row fileupload-buttonbar">
<div class="span7">
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-small btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span>Select and Upload File</span>
<input type="file" name="upload[upload]" id="upload_upload" />
</span>
</div>
</div>
输入没有隐藏,跨度在同一个div中找到。我当然尝试过“#upload_upload”作为选择器,结果是一样的。在规范中,我show()
稍后将这两行添加到输入中,没有它们的结果是相同的。
任何帮助表示赞赏。