Bdd

Bdd brings you cucumber-style Given/When/Then/And/But test reports

Status

Our Tests Latest Version # of Downloads Contribute
Master Build Status Gem Version Downloads GitHub Issues

GitHub License

Description

This gem brings two major functionality to your tests

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

Installation

Include in your Gemfile:

group :test do
  # pick one
  gem 'bdd', require: 'bdd/rspec'
  gem 'bdd', require: 'bdd/minitest'
end

Installation For RSpec

group :test do
  gem 'rspec'
  gem 'bdd', require: 'bdd/rspec'
end

Add this to your spec/spec_helper.rb file.

RSpec.configure do |config|
  config.color = true
  config.default_formatter = Bdd::RSpec::Formatter
end

# optionally, define methods in your own language

Bdd.define(%w[Dado], %w[Quando Entao], %w[E Mas]) # Portuguese
Bdd.define(%w[Zakładając], %w[Jeśli To], %w[Także Ale]) # Polish

Installation For Minitest

group :test do
  gem 'minitest'
  gem 'minitest-reporters'
  gem 'bdd', require: 'bdd/minitest'
end

Add this to your test/test_helper.rb file.

Minitest::Reporters.use!(Bdd::Minitest::Reporter.new)

# optionally, add methods in your own language

Bdd.define(%w[Dado], %w[Quando Entao], %w[E Mas]) # Portuguese
Bdd.define(%w[Zakładając], %w[Jeśli To], %w[Także Ale]) # Polish

Usage

File spec/features/search_spec.rb

context 'Searching' do
  it 'Result is found' do
    Given 'I am on the 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 the word result' do
      expect(page).to have_content('Result')
    end
  end
end

Run tests

rspec -fd spec/features/search_spec.rb

Output


<b>Searching</b>
  <b>Result is found</b>
    <b>Given</b> I am on the search page
    <b> When</b> I search something
    <b> Then</b> I should see the word result

More Examples





Defining custom steps

In case your flow is different and you would like to define your own wording.

You can add more English words, or add an entirely new language:

Bdd.define(%w[Given], %w[When Then], %w[And But]) # English
Bdd.define(%w[Dado], %w[Quando Entao], %w[E Mas]) # Portuguese
Bdd.define(%w[Zakładając], %w[Jeśli To], %w[Także Ale]) # Polish

Authors

Contributing

  1. Fork it ( https://github.com/thejamespinto/bdd/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Alternatives and Inspiration


  <b>rspec-steps</b>, <b>rspec-given</b> and <b>rspec-example_steps</b> run <i>AS</i> examples.
  <b>bdd</b> and <b>cucumber</b> run <i>INSIDE</i> examples, running tests faster.