Git Product home page Git Product logo

cucumber-the's Introduction

Cucumber::The

Build Status

Adds quick access to instances to help you write more fluid steps.

Given 'a published post' do
  The[:post] = FactoryGirl.create :post, :published
end

Given 'I publish a post' do
  The.post = FactoryGirl.create :post, :published, user: The(:logged_in_user)
end

When 'I go to the post' do
  visit post_path The.post
end

Then 'I should see the post title' do
  page.should have_content The[:post].title
end

Note that this gem does not generate anything for you, it's up to you to use this to write your own steps in your own style.

Why?

It's an eyesore to see scenarios like this:

Scenario: Displaying post tags
  Given a post titled "10 things you can do with a broken dishwasher"
  And that the post "10 things you can do with a broken dishwasher" has the tags "topten" and "hackery"
  When I go to the post "10 things you can do with a broken dishwasher"
  Then I should see "topten" and "hackery"

It reads a lot better like this:

Scenario: Displaying post tags
  Given a post titled "10 things you can do with a broken dishwasher"
  And that the post has the tags "topten" and "hackery"
  When I go to the post
  Then I should see the tags

Note how we can say "the post" and "the tag" instead of referring to the raw data in them. Also note how the second scenario is easier to extend with additional logic, for example:

Then 'I should see the tags' do
  The.tags.each do |tag|
    page.should have_css('.tag', text: tag.name)
  end
end

Why not just variables?

You can implement this yourself by using instance variables, but it has one major drawback:

Every time you want to read the variable, you'll need to check that it is set and fail otherwise. If you don't you'll get NoMethodError on NilClass further down the stack, making for a very bad experience for the user.

At that point, you start wrapping these up inside a method and bam, you've implemented this gem. If you don't want the extra dependencies, skip this gem and implement it yourself. If you want to save some time, just use this gem instead of reinventing the wheel.

Installation

Add this line to your application's Gemfile:

gem 'cucumber-the', require: false, group: :test

And then execute:

$ bundle

Then, require 'cucumber-the' inside features/support/env.rb (or a similar one that you control).

Documentation

You can read the documentation using Relish.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write tests
  4. Implement feature
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

Ruby versions

This gem supports the following versions of Ruby:

  • MRI 1.9.3
  • MRI 2.0
  • MRI 2.1
  • JRuby latest
  • Rubinius latest

cucumber-the's People

Contributors

mange avatar

Watchers

 avatar  avatar  avatar

cucumber-the's Issues

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.