我一直在寻找互联网,但我似乎无法让这个工作.
我想做的就是发送一个post请求并在rspec中测试响应.
这是我在controller_spec中的内容:
it 'my test' do
post 'api/company_id', :parameters => {key => 'value'}
response.should be_success
end
Run Code Online (Sandbox Code Playgroud)
我收到此错误:意外的$ end,期待keyword_end(SyntaxError)
这是post语句发生的行(代码块中的第二行).
我很难过,但任何帮助都会很棒.
我正在尝试用水豚和黄瓜测试一个帖子请求.我无法访问页面并按下链接发送请求,因为它有一个确认对话框,我没有使用javascript工作,所以我试图使用post方法,然后测试它是否重定向到适当的网址但是我得到了:
No response yet. Request a page first. (Rack::Test::Error)
Run Code Online (Sandbox Code Playgroud)
我的代码是:
page.driver.post url
page.driver.status_code.should be 302
follow_redirect!
Run Code Online (Sandbox Code Playgroud)
它工作正常,直到follow_redirect!.我试过page.driver.follow_redirects!但它也不起作用.
有帮助吗?
您好我遇到了railstutorial的问题.
我有测试文件 features/static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "Should have the content 'Sample App'" do
visit '/static_pages/home'
page.should have_conent('Sample App')
end
end
end
Run Code Online (Sandbox Code Playgroud)
我跑的时候 bundle exec rspec spec/features/static_pages_spec.rb
我收到以下错误:
Failures:
1) Static pages Home page Should have the content 'Sample App'
Failure/Error: page.should have_conent('Sample App')
NoMethodError:
undefined method `has_conent?' for #<Capybara::Session>
# ./spec/features/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.05262 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/static_pages_spec.rb:6 # Static pages …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Rails 项目,其中我使用 Rspec 与 Capybara 进行单元测试以访问页面。我有这个真实的网址:课程 IDhttp://localhost:3000/teacher/courses/2778/audience在哪里2778,此页面显示了登录的教师该课程中的学生(观众)。
我routes.rb的这个资源看起来像这样:
...
namespace :teacher do
...
resources :courses, except: [:delete] do
member do
...
get :audience
...
end
end
end
Run Code Online (Sandbox Code Playgroud)
在我的单元测试中,我已经以特定教师的身份登录,并且有一个@course代表相关课程的变量,现在,我需要直接转到该网址或路径。我已经尝试过:
visit '/teacher/courses/@course.id/audience'
visit '/teacher/courses/' + @course.id + '/audience'
visit '/teacher/courses/#{@course.id}/audience'
Run Code Online (Sandbox Code Playgroud)
但这些都没有奏效。
我怎样才能访问这条路径?
有没有办法将 HTTP 标头添加到 Capybara 请求/测试中。
我正在使用以下宝石。
capybara (2.4.4)
capybara-webkit (1.5.2)
chromedriver-helper (1.0.0)
rails (4.2.6)
Run Code Online (Sandbox Code Playgroud)
以下是水豚设置:
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :chrome
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
driver.browser.save_screenshot(path)
end
Run Code Online (Sandbox Code Playgroud) 我有一个下拉菜单。我希望水豚浏览它并找到特定元素并单击它。我目前正在尝试执行一个 inside 子句,并让它遍历列表并找到这个元素:“Cow_poop”
<div class="ant-select-selection ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="7256666c-da5f-48d6-c8fc-a249a4ed0fc9" aria-expanded="false" tabindex="0">
<div class="ant-select-selection__rendered">
<div class="ant-select-selection-selected-value" title="cow_poop" style="display: block; opacity: 1;">cow_poop</div>
<div class="ant-select-search ant-select-search--inline" style="display: none;">
<div class="ant-select-search__field__wrap">
<input autocomplete="off" class="ant-select-search__field" value="">
<span class="ant-select-search__field__mirror"> </span>
</div>
</div>
</div>
<span class="ant-select-arrow" unselectable="on" style="user-select: none;">
<i aria-label="icon: down" class="anticon anticon-down ant-select-arrow-icon">
<svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path>
</svg>
</i> …Run Code Online (Sandbox Code Playgroud) 我知道水豚使用原生的,我需要为此安装 gem 吗?
我在搜索框中输入后尝试按 Enter
我在水豚有2个场景.第一个检查页面上是否存在链接,第二个检查是否存在链接.
我能够通过使用以下方法获得第一次测试:
expect(page).to have_link('act_id')
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下方法进行第二次测试.
expect(page).to not_have_link('act_id')
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误
NoMethodError: undefined method `not_have_link'
Run Code Online (Sandbox Code Playgroud)
如何测试页面上是否存在链接?
Ruby版本:2.2
Rails版本:4.2
我的项目工作正常,之后我更新了宝石,现在它开始给我一些xpath的错误