monkey patch using capybara

9 views
Skip to first unread message

wbsu...@gmail.com

unread,
Dec 10, 2015, 4:30:43 PM12/10/15
to Ruby on Rails: Talk

 I am using capybara minitest on windows using selenium driver .. webkit driver would require me to install QT so I am avoiding that

 I am trying to simulate things like http error on an ajax request. I have this test in my feature as shown below.
I have a library that I include in my real controller, I then monkey patch that in my test to throw a 500 error. This seems to work,
but if I run "rake test:features" the tests all do not run because the monkey patch effects the other tests it seems. I am not sure there is a better approach ?
otherwise my tests have to be run individually somehow

the call: all('.submit-btn').first.click causes the controller submit_req action ..

============================================

require "test_helper"

Capybara.default_max_wait_time = 18

require "main_controller_lib"

# Monkey Patch here:
module MainControllerLib
  def submit_req
    puts "in submit stub"
    render :text => "http error", :status => 500
  end
end

feature "Will handle ajax errors" do

  scenario "ajax http error on main page", js: true do
    visit "/main/index"
    all('.submit-btn').first.click
  
    page.must_have_css(".fa-exclamation-circle")
    el = page.find('.fa-exclamation-circle')[:tooltip]
    assert_equal el, "Error on Submit:http error"
  end
end
Reply all
Reply to author
Forward
0 new messages