GithubHelp home page GithubHelp logo

rspec_variants's Introduction

RSpec Variants

Gem Version License

Dependency Status

RSpec Variants adds an expressive layer to RSpec by allowing for test syntax based on explicit data conditions and test conditions, including a tabular syntax for the concise specification of related data.

Installation

To get the latest stable release, add this line to your application's Gemfile:

gem 'rspec_variants'

To get the latest code:

gem 'rspec_variants', git: 'https://github.com/jeffnyman/rspec_variants'

After doing one of the above, execute the following command:

$ bundle

You can also install RSpec Variants just as you would any other gem:

$ gem install rspec_variants

Usage

All you have to do is require rspec_variants from your spec_helper file. Then you can use the DSL provided to structure your tests.

An example of using the data and test conditions:

    context 'Rocky Planets' do
      data_condition(:planet, :weight) do
        [
          ['mercury', '75.6'],
          ['venus', '181.4'],
          ['mars', '75.4'],
          ['pluto', '13.4']
        ]
      end

      test_condition do
        it 'data condition: 200 pound weight' do
          expect(on(Planet).send("#{planet}").value).to eq(weight)
        end
    end

Here the planet and the weight values in the expect statement in the test_condition are referring to those same elements specified in the data_condition. In this case, RSpec will execute the test condition block for each one of the elements in the data condition block.

You can also use a tabular format for the above example, which would look like this:

    context 'Rocky Planets' do
      data_condition(:planet, :weight) do
        'mercury' | '75.6'
        'venus'   | '181.4'
        'mars'    | '75.4'
        'pluto'   | '13.4'
      end

      test_condition do
        it 'test condition: 200 pound weight' do
          on(Planet).confirm_weight_on(planet).is_exactly(weight)
        end
      end
    end

You can also check out the variants_spec unit test for more examples.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake spec:all to run the tests. The default rake command will run all tests as well as a RuboCop analysis. To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jeffnyman/rspec_variants. The testing ecosystem of Ruby is very large and this project is intended to be a welcoming arena for collaboration on yet another test-supporting tool. As such, contributors are very much welcome but are expected to adhere to the Contributor Covenant code of conduct.

The RSpec Variants gem follows semantic versioning.

To contribute to RSpec Variants:

  1. Fork the project.
  2. Create your feature branch. (git checkout -b my-new-feature)
  3. Commit your changes. (git commit -am 'new feature')
  4. Push the branch. (git push origin my-new-feature)
  5. Create a new pull request.

Author

Credits

RSpec Variants is based off of RSpec::Parameterized. The reason for a new version rather than a fork is I wanted to re-situate this kind of logic based on the idea of data and test conditions, which I think is a bit more operative in the context in which it runs. I also want to be able to expand to different forms of variant expression.

License

RSpec Variants is distributed under the MIT license. See the LICENSE file for details.

rspec_variants's People

Contributors

jeffnyman avatar

Watchers

James Cloos avatar  avatar

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.