1

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 => "first@company.com"
      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 => "first@company.com"
click_button "Register"

and asserting the response by using capybara_minitest_spec:

page.must_have_content "Password"
page.must_have_button "Register"
barerd
  • 835
  • 3
  • 11
  • 31

1 Answers1

0

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.

Community
  • 1
  • 1
Steve
  • 15,606
  • 3
  • 44
  • 39
  • Unfortunately, the errors didn't change. Neither `Capybara.app = Kimsin.new` or the code above did make any change. The problem is probably either in my code (app or test) or there is a mismatch in the versions maybe. – barerd Jun 16 '12 at 21:46
  • I can't see what is going wrong in `test_index` because you have not included the assertion code. In `test_create_user` `within "//form#register" do` should be `within "form#register" do` - you seem to be mixing up xpath and css style expressions here. Finally I think that you will find that Capybara requires strings arguments for selectors so `fill_in :email ...` should be `fill_in 'email' ...` etc. – Steve Jun 17 '12 at 09:14
  • All tests (including webrat) pass with your suggestions. Thanks a lot! – barerd Jun 17 '12 at 22:04