Giter Club home page Giter Club logo

rspec-example_steps's Introduction

RSpec example steps

Given/When/Then/And/But steps for RSpec examples

Description

This gem brings two major functionality to your spec/features

  • Verbosity for rspec documentation formatter.
  • Ability to comment or describe set of actions in example into some step.

Installation

  • For rspec v2 use gem v0.2.x or rspec2 branch
  • For rspec v3 use gem v3.x.x or master branch
gem 'rspec-example_steps'

Add to spec/spec_helper.rb

require 'rspec/example_steps'

Example

spec/features/search_spec.rb

context 'Searching' do
  Steps 'Result found' do
    Given 'I am on search page' do
      visit '/search'
      expect(page).to have_content('Search')
    end

    When 'I search something' do
      fill_in 'Search', with: 'John'
      click_button 'Go'
    end

    Then 'I should see result' do
      expect(page).to have_content('Result')
    end
  end
end

Documentation formatting output:

rspec -fd spec/features/search_spec.rb

Searching
  User succesfully replaces device
    Given I am on search page
    When I search something
    Then I should see result

Pending steps

Simular to Example :pending behavior:

Steps 'User login' do
  # just skip block
  When 'I go to login'

  # pass pending: true option
  Then 'I should see welcome', pending: true do
  ...
  end

  # pass pending: 'some pending message'
  Then 'I should see last login IP', pending: 'WIP' do
  ...
  end
end

Authors

License

Alternatives

rspec-example_steps's People

Contributors

amishyn avatar ayanko avatar jraines avatar le0pard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rspec-example_steps's Issues

uninitialized constant RSpec::Core::ExampleGroup::MetadataHashBuilder

Tried using rspec 2.11.1

Shows this error upon trying to load the gem

uninitialized constant RSpec::Core::ExampleGroup::MetadataHashBuilder (NameError)
/Users/Sebastian/.rvm/gems/ruby-1.9.3-p194@aurum/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:16:in <class:ExampleGroup>' /Users/Sebastian/.rvm/gems/ruby-1.9.3-p194@aurum/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:15:inmodule:Core'
/Users/Sebastian/.rvm/gems/ruby-1.9.3-p194@aurum/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:2:in <module:RSpec>' /Users/Sebastian/.rvm/gems/ruby-1.9.3-p194@aurum/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:1:in<top (required)>'
/Users/Sebastian/.rvm/gems/ruby-1.9.3-p194@aurum/gems/rspec-example_steps-0.2.1/lib/rspec/example_steps.rb:3:in `<top (required)>'

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

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

wrong order in output with capybara

With this spec

feature "Feature Admin Customer" do
  given(:admin){create_admin}
  scenario "View all customers" do
    Given 'I login as admin ' do
      login_as(admin)
    end
    When 'I click on Customers link' do
      click_link_on_admin_menu_bar("Customers")
    end
    Then 'I should see customers list' do
      expect(current_path).to eq(admin_customers_path)
      expect(page).to have_css 'body.admin_customers', :visible => true
    end
  end
end

Output in terminal:

Feature Admin Customer
    Given I login as admin 
    When I click on Customers link
    Then I should see customers list
  View all customers

License missing from gemspec

Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec
via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Bundler now generates gems with a default 'MIT' license. There is even a License Finder
to help companies ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec.
Including a license in your gemspec is a good practice, in any case.

If you need help choosing a license, github has created a license picker tool

How did I find you?

I'm using a script to collect stats on gems, originally looking for download data, but decided to collect licenses too,
and make issues for gemspecs not specifying a license as a public service :)
So far it's going pretty well.
I've written a blog post about it

unable to use "it " block inside shared example block

Hi ,

I am not able to use "it" block inside "shared_steps" block as described in below link.
https://github.com/LRDesign/rspec-steps
code
shared_steps_with_itblock

Error Message
error_msg

but other example worked fine that has When, Given,And and Given blocks provided under below link .

https://github.com/railsware/rspec-example_steps

code
shared_steps_with_gerkin

could you please help me in understanding below points

can i use "it " block under "shared_steps" ?

is gem 'rspec-example_steps' supports Gherkin Language by default?

for example, if i am using multiple steps under "describe " block , how to skip remaining steps , if one step fail?

Along with Step block description I would like to add (Given, When, And, Then ) blocks description to HTML report . please let me know different gems/ways that are available to support this.

thanks,
Chandana

About deleted methods

Sorry for my bad english.

I want to know why delete shared_steps and include_steps.
Should i use rspec-steps as an alternative ?

Thank you.

Missing rspec output

I am no longer getting rspec output for steps. It shows the output for Steps in white but doesn't print output for Given, When, Then etc. Did something change?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.