Giter Club home page Giter Club logo

minitest-capybara's Introduction

minitest-capybara

Build Status

โš ๏ธ This gem is no longer maintained as Capybara has added Minitest support upstream, use that instead.

Capybara matchers support for Minitest unit & spec.

Why?

Capybara has good support for RSpec.

If you want to use it with Minitest, you can of course write:

assert page.has_content?("Hello")

but:

  1. it's kinda ugly
  2. you don't have meaningfull error messages.

With this project Minitest gets all the good stuff.

Rails integration

minitest-capybara (and capybara) works with Rails out of the box, remember to require capybara/rails.

See example Rails app: https://github.com/wojtekmach/minitest-capybara-example.

For more features, check out: minitest-rails-capybara.

Usage

With minitest/test:

class HomeTest < Minitest::Capybara::Test
  def test_home
    visit "/"

    assert_content "Homepage"

    within ".login" do
      refute_content "Signed in as"
    end

    assert_link "Sign in"
    assert_link find(".login"), "Sign in"

    assert_selector 'li:first', text: "Item 1"
  end
end

With minitest/spec:

class HomeSpec < Minitest::Capybara::Spec
  it "works" do
    visit "/"

    page.must_have_content "Homepage"

    within ".login" do
      page.wont_have_content "Signed in as"
    end

    find(".login").must_have_link("Sign in")

    page.must_have_selector 'li:first', text: "Item 1"
  end
end

Instead of inheriting directly from Minitest::Capybara::Test (or Spec) it's usually better to create a custom test base class:

# test/acceptance_test_helper.rb
require "minitest/autorun"

class AcceptanceTest < Minitest::Capybara::Test
  # custom methods, before blocks etc.
end

If you need to inherit from a different base class (e.g. ActiveSupport::TestCase) you can do this instead:

# test/acceptance_test_helper.rb
require "test_helper"

class AcceptanceTest < ActiveSupport::TestCase
  include Minitest::Capybara::Behaviour

  # custom methods, before blocks etc.
end

Capybara drivers

Switching drivers is easy with minitest-metadata:

require 'minitest-metadata'

class AcceptanceSpec < Minitest::Capybara::Spec
  before do
    if metadata[:js]
      Capybara.current_driver = Capybara.javascript_driver
    else
      Capybara.current_driver = Capybara.default_driver
    end
  end
end

class HomeSpec < AcceptanceSpec
  it "home with ajax", js: true do
    visit "/"
    page.must_have_content "AJAX enabled..."
  end
end

License

minitest-capybara is released under the MIT License.

minitest-capybara's People

Contributors

acnalesso avatar apotonick avatar blowmage avatar gui avatar jonatack avatar joseramonc avatar patru avatar searls avatar wojtekmach 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  avatar  avatar

Watchers

 avatar  avatar  avatar

minitest-capybara's Issues

Use Capybara 3.x

Hi, thanks a lot for writing this gem! ๐Ÿ˜„
I'd like to use it with the latest Capybara (v3). I tried simply updating the dependency and it worked fine.

What are the changes that would need to be done to support Capybara 3?
I'm happy to work on it if you could point me to the right direction.
Thanks!

Integration issue with spec (`describe` blocks)

Thanks for writing this gem, it seems super useful.

I'm having trouble using this in a project that uses MiniTest::Spec. It doesn't create any Spec classes, instead opting for just plain describe blocks, via Capybara::DSL.

require "features_helper"

describe "this feature" do
 # ...
end

Inside features_helper.rb we have:

class MiniTest::Spec
  include Capybara::DSL
end

I added require "minitest/capybara" but it didn't work.
Do I need to open a class and include Minitest::Capybara::Behaviour?

implicit dependency on capybara 2.1.0

This is more for reference than a real issue, but there is a small dependency of the master branch on capybara 2.1.0. As I am stuck with Ruby 1.9.2 I can only use capybara 2.0.3 at the moment. assert_link (and other dynamically created methods from capybara/assertions.rb) rely on Capybara::Helpers.failure_message being present (which only got defined in capybara 2.1.0). For this reason they throw an exception when they fail (but only then, thanks to the dynamic nature of Ruby). So your existing tests are all fine, but you have a pretty hard time figuring out which assertion failed if anything breaks.

As this is easily fixed using the code in the following Gist

https://gist.github.com/Patru/6623747

this is hardly worth fixing, but it is probably easier to find this way.

uninitialized constant MiniTest::Capybara::Assertions::Capybara (NameError)

I ran into this error:

uninitialized constant MiniTest::Capybara::Assertions::Capybara (NameError)

The full line looks like this:

/Users/abatko/.rvm/gems/ruby-1.9.3-p448@hello/gems/minitest-capybara-0.3.0/lib/minitest/capybara.rb:6:in `<module:Assertions>': uninitialized constant MiniTest::Capybara::Assertions::Capybara (NameError)

Downgrading to 0.1.0 resolved the issue.

I am not be able to downgrade to 0.2.0 without having to make additional dependency changes:

Bundler could not find compatible versions for gem "capybara":
  In Gemfile:
    minitest-capybara (= 0.2.0) ruby depends on
      capybara (~> 1.0) ruby

    minitest-rails-capybara (~> 0.9.0) ruby depends on
      capybara (2.1.0)

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.