0

I have the following test...

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

...and here is the error message I am getting...

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

Note line 24 is visit '/events'

Here are capybara and xpath gems...

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)

first text going to '/' works OK, but not '/events'. Did find some clues on regarding various versions of capybara and xpath gems. I tried specifying some earlier versions of those gems in my Gemfile, but still no worky.

Edit

Here are relevant lines from 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

Line 19 is @events = Event.active.order('session_start DESC').page(params[:page])

Community
  • 1
  • 1
Mark Locklear
  • 5,044
  • 1
  • 51
  • 81

1 Answers1

0

First off, you should break that up into individual scenarios / tests since you're asserting different things.

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

Please post your events controller since that is where the error is getting triggered. when you visit /events.

UPDATE:

You are running into a conflict between Capybara's page method and your pagination, which I assume is either based on Kaminari or will_paginate.

You have this warning that confirms this:

including Capybara::DSL in the global scope is not recommended!

so remove Capybara::DSL from your spec_helper.rb.

Community
  • 1
  • 1
tirdadc
  • 4,603
  • 3
  • 38
  • 45