Coder Social home page Coder Social logo

minitest-metadata's Introduction

minitest-metadata

Build Status

Description

minitest-metadata allows you to set metadata (key-value) for your test cases so that before and after hooks can use them.

You can use it to:

  • change environments (prepare drivers, mocks etc)
  • mark tests as slow, fast or (God forbid) order dependant

Example

require 'minitest/autorun'
require 'minitest-metadata'

describe 'thing' do
  it 'does stuff', vcr: true do
    puts metadata[:vcr] # => true
  end
end

Example with capybara

Suppose you want to tag some of your Capybara acceptance tests to use JavaScript driver

class AcceptanceTest < MiniTest::Spec
  include Capybara::DSL

  before do
    if metadata[:js] == true
      Capybara.current_driver = Capybara.javascript_driver
    end
  end

  after do
    Capybara.current_driver = Capybara.default_driver
  end
end

class UsersAcceptanceTest < AcceptanceTest
  it "basic pagination" do
    visit "/users"
    assert page.has_content?("Current page: 1")

    click_link "Next page"

    assert page.has_content?("Current page: 2")
  end

  it "keyboard shortcuts pagination", :js => true do
    visit "/users"
    assert page.has_content?("Current page: 1")

    press_key "n"

    assert page.has_content?("Current page: 2")
  end
end

As in RSpec, more compact syntax can be used:

it "keyboard shortcuts pagination", :slow, :wip, :driver => :poltergeist

Note about speed

minitest-metadata adds some overhead so you might want to limit it to only acceptance specs. If that's the case do this:

# Gemfile

group :test do
  gem 'minitest-metadata', :require => false
end

# test/acceptance_test_helper.rb
require 'minitest/metadata'

class AcceptanceTest < MiniTest::Spec
  include MiniTest::Metadata
end

Requirements

  • minitest

Instalation

gem install minitest-metadata

or put in a Gemfile:

gem 'minitest-metadata'

License

(The MIT License)

Copyright (c) 2012-2014 Wojciech Mach

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

minitest-metadata's People

Contributors

bbozo avatar simi avatar wojtekmach avatar

Watchers

 avatar  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.