Skip to content

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

Open
@raihan2006i

Description

@raihan2006i

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 = 'student@example.com'
    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions