1
votes

I am trying to test a sinatra app using minitest and capybara but get several errors on all tests using capybara features like fill_in or visit.

test_index gives:

undefined local variable or method `app' for #

test_create_user gives:

Invalid expression: .////form[@id = 'register']

test_same_email gives:

Unable to find css "#register"

test_login gives:

cannot fill in, no text field, text area or password field with id, name, or label 'email' found

Any suggestions on what may be wrong?

test.rb

require "test/unit"
require "minitest/autorun"
require "capybara"
require "capybara/dsl"
require "rack/test"
require_relative "../lib/kimsin.rb"

ENV["RACK_ENV"] = "test"

class KimsinTests < Test::Unit::TestCase
  include Rack::Test::Methods
  include Capybara::DSL
  Capybara.app = Sinatra::Application

  def test_index
    visit "/"
    assert stuff..
  end

  def test_create_user
    visit "/user/new"
    within "//form#register" do
      fill_in :username, :with => "[email protected]"
      fill_in :password, :with => "abC123?*"
      fill_in :confirm_password, :with => "abC123?*"
      click_link "Register"
    end
    assert stuff..
  end
end

I'm using cygwin 1.7.15-1 on windows 7, rvm -v 1.14.1 (stable) and ruby -v 1.9.2p320.

----UPDATE----

Finally I got the tests work by incorporating Steve's suggestions:

within "form#register" do
fill_in "email", :with => "[email protected]"
click_button "Register"

and asserting the response by using capybara_minitest_spec:

page.must_have_content "Password"
page.must_have_button "Register"
1

1 Answers

0
votes

I just answered a more recent question you posted about Sintra with Webrat.

Acceptance testing of sinatra app using webrat fails

I think the problem here is the same. Try replacing:

Capybara.app = Sinatra::Application

with:

Capybara.app = Kimsin

Personally I would choose Capybara over Webrat.