bernat / best_in_place

A RESTful unobtrusive jQuery Inplace-Editor and a helper as a Rails Gem
http://blog.bernatfarrero.com/in-place-editing-with-javascript-jquery-and-rails-3/
1.2k stars 572 forks source link

Testing with RSpec/Capybara #472

Open danielbonnell opened 9 years ago

danielbonnell commented 9 years ago

It would be nice to have some documentation on how to test with RSpec/Capybara. I'm spinning my wheels on a strange issue where a list of categories, whose titles are bip fields, do not show up on a page when it is viewed by Capybara. I've isolated the issue to a problem with the bip_area method call on this line of code in my spec: bip_area @category, :name, 'Test Category'

Here is my spec file:

require 'rails_helper'

feature 'admin edits category', %Q{
  As an admin, I want to edit a category or subcategory, so that it better
  represents the content under it.
  Acceptance Criteria:
  * [X] - I can edit the name of a category inline.
  * [X] - I can edit the name of a subcategory inline.
  } do

  let(:admin) do
    FactoryGirl.create(:user, admin: true)
  end

  before(:each) do
    @category = FactoryGirl.create(:category)
  end

  scenario 'admin edits category title', js: true, focus: true do
    log_in_as(admin)
    visit admin_categories_path

    bip_area @category, :name, 'Test Category'
    expect(page).to have_content @category.name
  end
end

If I set js: false or just exclude it, I get an error from Capybara: Capybara::Driver::Node#trigger.

I've scoured StackOverflow and haven't had any luck solving the problem. I have made a post of StackOverflow about the issue.

stereodenis commented 9 years ago

@danielbonnell could you provide a sample app with this spec?

danielbonnell commented 9 years ago

The Abh Nation. I've been trying to see if I can get the test to work using Capybara's standard .click and .fill_in methods, but they don't work with BIP so far as I can tell.

The only semi-useful resources I've found are two StackOverflow questions, but neither offer a complete solution that works. http://stackoverflow.com/questions/26100077/integration-testing-with-best-in-place-capybara-rspec http://stackoverflow.com/questions/19877371/has-anyone-ever-tested-best-in-place-test-helper-methods-with-rspec

I've also looked through the example unit tests and copied the format precisely, but to no avail. The test always fails because Capybara can't find the field.

drdevnull commented 9 years ago

related issue: https://github.com/bernat/best_in_place/issues/499

I'm having a similar problem with bip_area - I don't think it work...

oystersauce8 commented 8 years ago

pardon me if this was obvious, are you guys using a javascript-capable capybara driver? i use phantomjs for this kind of thing.