rspec-example_steps icon indicating copy to clipboard operation
rspec-example_steps copied to clipboard

Using rspec-rails (3.0.1), rspec-example_steps (3.0.2) and capybara not showing steps in output

Open raihan2006i opened this issue 10 years ago • 9 comments

When i run following rspec command steps are not showing

rspec -fd spec/features/student_signs_up_spec.rb

RSpec output

Student sign up
.  User tries with out first name and with other required fields
.  User tries with out last name and with other required fields

Here is the spec file

# spec/features/student_signs_up_spec.rb
require 'rails_helper'

feature 'Student sign up' do
  background do
    @school = create(:school)
    @first_name = 'John'
    @last_name = 'Smith'
    @grade = Student.allowed_grade_range.sample
    @email = '[email protected]'
    @password = '12345678'
  end

  scenario 'User tries with out first name and with other required fields' do
    When 'I am on sign up page' do
      visit new_user_registration_path
    end
    And 'I click on student tab' do
      click_link 'Student'
    end
    And 'I do not fill in first name' do
      fill_in 'user[student_attributes][first_name]', :with => nil
    end
    And 'I fill in last name' do
      fill_in 'user[student_attributes][last_name]', :with => @last_name
    end
    And 'I fill in email' do
      fill_in 'user[email]', :with => @email
    end
    And 'I fill in password' do
      fill_in 'user[password]', :with => @password
    end
    And 'I fill in password confirmation' do
      fill_in 'user[password_confirmation]', :with => @password
    end
    And 'I select school' do
      select(@school.name, :from => 'user[student_attributes][school_id]')
    end
    And 'I select grade' do
      select(@grade, :from => 'user[student_attributes][grade]')
    end
    And 'I click on Sign up button' do
      click_button 'Sign up'
    end
    Then 'I should in sign up page' do
      expect(current_path).to eq('/users')
    end
    Then 'I should see error on first name' do
      expect_field_error("user[student_attributes][first_name]")
    end
  end

  scenario 'User tries with out last name and with other required fields' do
    When 'I am on sign up page' do
      visit new_user_registration_path
    end
    And 'I click on student tab' do
      click_link 'Student'
    end
    And 'I fill in first name' do
      fill_in 'user[student_attributes][first_name]', :with => @first_name
    end
    And 'I do not fill in last name' do
      fill_in 'user[student_attributes][last_name]', :with => nil
    end
    And 'I fill in email' do
      fill_in 'user[email]', :with => @email
    end
    And 'I fill in password' do
      fill_in 'user[password]', :with => @password
    end
    And 'I fill in password confirmation' do
      fill_in 'user[password_confirmation]', :with => @password
    end
    And 'I select school' do
      select(@school.name, :from => 'user[student_attributes][school_id]')
    end
    And 'I select grade' do
      select(@grade, :from => 'user[student_attributes][grade]')
    end
    And 'I click on Sign up button' do
      click_button 'Sign up'
    end
    Then 'I should in sign up page' do
      expect(current_path).to eq('/users')
    end
    Then 'I should see error on first name' do
      expect_field_error("user[student_attributes][last_name]")
    end
  end


  def expect_field_error(field_name)
    expect(page).to have_xpath("//*[@name='#{field_name}']/following-sibling::span[contains(@class,'text-danger')]")
  end
end

raihan2006i avatar Jul 06 '14 17:07 raihan2006i

Use Steps instead of scenario.

ayanko avatar Jul 06 '14 17:07 ayanko

@ayanko Thanks for your reply. I changed scenario to Steps. Now output is like below.

Student sign up
..

raihan2006i avatar Jul 06 '14 17:07 raihan2006i

@ayanko Any clue how to solve this issue?

raihan2006i avatar Jul 08 '14 23:07 raihan2006i

scenario 'User login', with_steps: true do ...

ayanko avatar Jul 09 '14 06:07 ayanko

@ayanko I changed my code as you suggested, but still steps are not showing in output

raihan2006i avatar Jul 11 '14 03:07 raihan2006i

3.0.2 is quite old nowadays. Did you reproduce an issue with recent rspec-example_steps and rspec ?

ayanko avatar Mar 11 '15 22:03 ayanko

@raihan2006i Any updates?

ayanko avatar Jun 28 '16 21:06 ayanko

Old issue, but I am running into a similar problem and did some debugging

It seems that the setup code is not properly registering the new listener https://github.com/railsware/rspec-example_steps/blob/f6236f6103c28805fe3d9c4257ed94ab4760e754/lib/rspec/example_steps.rb#L22-L25

If you require 'rspec/example_steps' in spec_helper.rb DocumentationFormatter is not yet registered at that point, so it doesn't register the listener

However, if you paste the same lines into spec_helper.rb after configuring the formatter, it works fine:

RSpec.configure do |config|
  config.formatter = :documentation

  formatter = RSpec.world.reporter.find_registered_formatter(RSpec::Core::Formatters::DocumentationFormatter)
  RSpec.world.reporter.register_listener formatter,
                                         :example_started, :example_step_passed, :example_step_pending, :example_step_failed

# etc

end

I've never mucked around with this part of RSpec before, so I'm not sure what the proper solution is

FYI — I'm on: rspec-core (3.6.0) rspec-rails (3.6.0) rspec-example_steps (3.0.2)

atomanyih avatar Oct 03 '17 22:10 atomanyih

Old issue, but I am running into a similar problem and did some debugging

It seems that the setup code is not properly registering the new listener rspec-example_steps/lib/rspec/example_steps.rb

Lines 22 to 25 in f6236f6

if formatter = RSpec.world.reporter.find_registered_formatter(RSpec::Core::Formatters::DocumentationFormatter) RSpec.world.reporter.register_listener formatter, :example_started, :example_step_passed, :example_step_pending, :example_step_failed end If you require 'rspec/example_steps' in spec_helper.rb DocumentationFormatter is not yet registered at that point, so it doesn't register the listener

However, if you paste the same lines into spec_helper.rb after configuring the formatter, it works fine:

RSpec.configure do |config|
  config.formatter = :documentation

  formatter = RSpec.world.reporter.find_registered_formatter(RSpec::Core::Formatters::DocumentationFormatter)
  RSpec.world.reporter.register_listener formatter,
                                         :example_started, :example_step_passed, :example_step_pending, :example_step_failed

# etc

end

I've never mucked around with this part of RSpec before, so I'm not sure what the proper solution is

FYI — I'm on: rspec-core (3.6.0) rspec-rails (3.6.0) rspec-example_steps (3.0.2)

I tried your solution. I am getting error, undefined method `example_started' for nil:NilClass (NoMethodError)

/Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:201:in block in notify': undefined method example_started' for nil:NilClass (NoMethodError) from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:200:in each' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:200:in notify' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:121:in example_started' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:463:in start' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:430:in fail_with_exception' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:598:in block in run' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:639:in each' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:639:in for_filtered_examples' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:598:in rescue in run' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:604:in run' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in block (3 levels) in run_specs' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in map' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in block (2 levels) in run_specs' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1989:in with_suite_hooks' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:111:in block in run_specs' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:74:in report' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:110:in run_specs' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:87:in run' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in run' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in invoke' from /Library/Ruby/Gems/2.3.0/gems/rspec-core-3.8.0/exe/rspec:4:in <top (required)>' from /usr/local/bin/rspec:22:in load' from /usr/local/bin/rspec:22:in `

'

akash90khandelwal avatar Dec 29 '18 16:12 akash90khandelwal