Rspec e javascript

Dovrei testare, tramite rspec, un’action di un controller che viene
chiamata tramite javascript.
L’action e’:

def index
unless params[:customer_full_name].blank?
full_name = params[:customer_full_name]
@customers = Customer.search_full_name(full_name).paginate(:per_page
=> 10,
:page => params[:page])
else
@customers = Customer.all.paginate(:per_page => 10, :page =>
params[:page])
end
render :layout => false if request.xhr?
end

nella view c’e’ un campo di ricerca che, man mano che si inseriscono
dei valori, attiva una funzione javascript per una ricerca.
Non riesco a far funzionare il test:

require ‘spec_helper’
require ‘capybara/rspec’

describe CustomersController do
include Devise::TestHelpers

describe “search with js”, :js => true do
before(:each) do
@customers = mock_model(Customer, :full_name => “User-1”)
end

context "when full_name is 'user'" do
  it "should find customers" do
    login
    page.should have_content "Customers"
    page.should have_content "Dashboard"
    click_link('Customers')
    fill_in "customer_full_name", :with => "User"
    @full_name = "User"
    Customer.should_receive(:search_full_name).with(@full_name).and_return(@customers)
    @customers.should_receive(:paginate)
    do_get
    assigns(:customers).should_not be_nil
  end
end

def login
User.make!
visit ‘/d/users/sign_in/’
fill_in “user_email”, :with => “[email protected]
fill_in “user_password”, :with => “password”
click_button “Sign in”
end

def do_get page= nil, format = ‘html’
get ‘index’, :customer_full_name => @full_name, :format => format
end

Potete darmi qualche suggerimento?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs