我有以下测试...
describe 'non auth user' do
it 'welcomes the user' do
#visit home page
visit '/'
page.should have_content('Upcoming Sessions')
#visit all events
visit '/events'
page.should have_content('All Sessions')
#visit recent events
visit '/events/recent'
page.should have_content('Recent Sessions')
#visit upcoming events
visit '/events/upcoming'
page.should have_content('Upcoming Sessions')
end
end
...这是我得到的错误信息......
ruby-2.1.5@learn user:learn user$ rspec spec
UPGRADE WARNING: Honeybadger.configure was removed in v2.0 and has no effect. Please upgrade: https://www.honeybadger.io/s/gem-upgrade
including Capybara::DSL in the global scope is not recommended!
.F
Failures:
1) non auth user welcomes the user
Failure/Error: visit '/events'
ArgumentError:
wrong number of arguments (1 for 0)
# ./app/controllers/events_controller.rb:19:in `index'
# ./app/controllers/application_controller.rb:69:in `block in set_timezone'
# ./app/controllers/application_controller.rb:69:in `set_timezone'
# ./app/middleware/catch_json_parse_errors.rb:10:in `call'
# ./spec/integration/main_spec.rb:24:in `block (2 levels) in <top (required)>'
Deprecation Warnings:
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
now yield the example as a block argument, and that is the recommended
way to access the current example from those contexts.
- The current example is now exposed via `RSpec.current_example`,
which is accessible from any context.
- If you can't update the code at this call site (e.g. because it is in
an extension gem), you can use this snippet to continue making this
method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c|
c.expose_current_running_example_as :example
end
(Called from /Users/marklocklear/.rvm/gems/ruby-2.1.5@learn/gems/capybara-2.0.2/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
now yield the example as a block argument, and that is the recommended
way to access the current example from those contexts.
- The current example is now exposed via `RSpec.current_example`,
which is accessible from any context.
- If you can't update the code at this call site (e.g. because it is in
an extension gem), you can use this snippet to continue making this
method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c|
c.expose_current_running_example_as :example
end
(Called from /Users/marklocklear/.rvm/gems/ruby-2.1.5@learn/gems/capybara-2.0.2/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
2 deprecation warnings total
Finished in 0.44172 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec/integration/main_spec.rb:17 # non auth user welcomes the user
Randomized with seed 37582
注意第24行是访问&#39; / events&#39;
这是水豚和xpath宝石......
capybara (ruby-2.1.5@learn user:learn user$ gem list xpath && gem list capybara
*** LOCAL GEMS ***
xpath (2.0.0, 1.0.0)
*** LOCAL GEMS ***
capybara (2.4.4, 2.0.2).4.4, 2.0.2)
第一个文字转到&#39; /&#39;工作正常,但不是&#39; / events&#39;。找到了关于各种版本的水豚和xpath宝石的一些线索。我尝试在我的Gemfile中指定这些gems的一些早期版本,但仍然没有用。
以下是events_controller ...
的相关行def index
@list_title = 'All Sessions'
params[:page].present? ? (@page_title = "#{@list_title} - Page #{params[:page]}") : (@page_title = @list_title)
if(@conference)
@conference_display = true
@events = @conference.events.active.order('session_start ASC').page(params[:page])
@all_events_path = events_path
else
@events = Event.active.order('session_start DESC').page(params[:page])
end
end
第19行是@events = Event.active.order('session_start DESC').page(params[:page])
答案 0 :(得分:0)
首先,你应该将其分解为单独的场景/测试,因为你断言了不同的东西。
$var = 123456;
$jsonData->codeid = $var
请发布您的事件控制器,因为这是触发错误的地方。当您访问feature 'non auth user' do
scenario 'visits the homepage' do
visit '/'
page.should have_content('Upcoming Sessions')
end
scenario 'visits all events' do
visit '/events'
page.should have_content('All Sessions')
end
scenario 'visits recent events' do
visit '/events/recent'
page.should have_content('Recent Sessions')
end
scenario 'visits upcoming events' do
visit '/events/upcoming'
page.should have_content('Upcoming Sessions')
end
end
。
更新:
你在Capybara的页面方法和你的分页之间遇到conflict,我认为这是基于Kaminari或will_paginate。
您有此警告确认:
/events
所以从including Capybara::DSL in the global scope is not recommended!
删除Capybara::DSL
。