Coder Social home page Coder Social logo

simple_bdd's Introduction

Simple BDD

Simple BDD offers basic Behaviour Driven Development language syntax. It enables tests to take steps to become more declarative than imperative by hiding the implementation and revealing test intent. It can be used in any test framework as it's just a way to keep the collaborative business language within a test by calling methods which directly relate to the step in the test.

Installation

Add this line to your application's Gemfile:

gem 'simple_bdd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_bdd

Usage

Standard Usage

The following will call the commented method in scope of the current class or module. (Every RSpec describe block is an anonymous class.)

[Gg]iven "Some state" # calls some_state
[Ww]hen "this happens" # calls this_happens
[Tt]hen "this change occurs" # calls this_change_occurs
[Bb]ut "this other thing still happens" # calls this_other_thing_still_happens
[Aa]nd "this other side effect happens" # calls this_other_side_effect_happens

Behavior Usage

Some additional methods allow you to group related behaviors in your tests:

Given "Admin is signed in"

behavior "admin can manage widgets" do
  When "Admin views all widgets"
  Then "Admin sees the first widget"
end

behavior "admin can manage factories" do
  When "Admin views all factories"
  Then "Admin sees the first factory"
end

Any of the following names can be substituted for behavior above:

  • and_by
  • behaves_like
  • behavior
  • behaviour
  • by
  • it_also

RSpec

To use SimpleBDD in your tests, simply add the following line to your spec helper:

require 'simple_bdd/rspec'

Or, if you want to have more control, you can do this instead:

require 'simple_bdd'

RSpec.configure do |config|
  config.include SimpleBdd
end

By default, SimpleBDD marks specs pending on missing step implementations. You can change this behavior to raise an error instead in the spec helper:

RSpec.configure do |config|
  config.raise_error_on_missing_step_implementation = true
end

Contributing

  1. Fork it
  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 new Pull Request

simple_bdd's People

Contributors

andreapavoni avatar berlin-ab avatar danfinnie avatar gonzedge avatar mikfreedman avatar robb1e avatar travisp avatar zephyr-dev 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

Watchers

 avatar  avatar  avatar  avatar

simple_bdd's Issues

NoMethodError too aggresive

If the test code calls a method that doesn't exist it will throw a NoMethodError which will make the test pending suggesting your method can't be found instead of passing through the error.

SimpleBDD should check if the current context responds to the method instead of catching an error.

parameters for Given/When/Then/etc

I thought it would be nice to be able to do things like:

Given 'a user named', 'John'
When 'I enter a password', 'password for John'

It turns out this is really easy. I already have it working in this commit.

For my current purposes, I don't care that this is tested and such, but if the owner is interested in pulling this functionality in and does care to have it tested, I would be willing to consider doing that work.

Show line numbers for pending step

When a step is defined, but not implemented, the message should show the line number of the step. Currently only the line number of the scenario is shown.

Generate step methods

Writing all the methods is a bit tedious since the step's text can't be copy/pasted.

Is there any interest in a generator that would print all the missing methods in the terminal, or even append them to a spec file?

RSpec not loaded?

It seems that RSpec is not defined on the initial declaration of the configuration item:

module SimpleBdd
  class StepNotImplemented < StandardError; end

  RSpec.configuration.add_setting(:raise_error_on_missing_step_implementation,
                                  default: false) if defined?(::RSpec)

Which leads to this issue:

  1) Commenting through the activity page commenting on news comment activity
     Failure/Error: When "I add a comment"
     NoMethodError:
       undefined method `raise_error_on_missing_step_implementation?' for #<RSpec::Core::Configuration:0x007f9ed4cfac90>

I'm not sure if this is an issue with my local setup or what. Potentially, RSpec could be required in simple_bdd/rspec

require 'rspec'    # <============
require 'simple_bdd'

RSpec.configure do |config|
  config.include SimpleBdd
end

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.