Posted by admin
on April 09, 2013
I was just dealing again with “unresponsive script” errors in cucumber when I was testing if an error message appears on the page.
As always I used
page.should have_content "Error message"
and then Firefox got unresponsive and threw the error. I’ve even upped the default waiting time in the FF preferences (user.js), max_wait_timeout. However didn’t work for me either.
I now found a fix for this in using a different selector. I am going for XPath now and all is working fine.
page.should have_xpath("//*[text()='#{text}']", :visible => true)
Wonder if I should default to XPath.
Posted by admin
on April 08, 2013
When running VCR for a cucumber selenium test it will record by default every request. Unfortunately every button click results in a Selenium URI request, and each uri has a unique session key that will change for each run, so you end up having a file of 9000 lines for a single run and 18000 for the 2nd run.
Fortunately VCR comes with a simple ignore port configuration so you can ignore these requests.
VCR.configure do |c|
c.hook_into :webmock
c.cassette_library_dir = File.expand_path('../../cassettes', __FILE__)
c.allow_http_connections_when_no_cassette = true
c.ignore_request do |request|
URI(request.uri).port == 7055
end
end
Posted by admin
on April 05, 2013
Habe gerade angefangen Ingress zu spielen. Da ich keine gutes Forum gefunden haben, habe ich gedacht ich erstelle selbst eines.
Dieses “Ingress Forum” ist nun unter www.ingress-forum.at zu finden.
Posted by admin
on March 28, 2013
In my current application I need to have one job not beeing invoked more than once and another job having at least a minimum of 5 retries before it stops.
There’s not much in the documentation about this, but there was a patch that made this possible. Simply add a method max_attempts into your job.
class MyJob < Struct.new(:id)
def max_attempts
5
end
def perform
end
end
Posted by admin
on January 23, 2013
Just opened up an issue pointing out a bug that is related to a devise change allowing either to use a login or user name. If you try to resend the confirmation message and a user is alread confirmed the user did not see the error message.
Issue on github
Posted by admin
on January 14, 2013
I am currently working on an API that allows client to create new records. If a JSON request however contains an invalid JSON response an exception is called an a 500, internal server error is returned to the client.
Thats of course not the desired way because it is a client error and not an actual server error. As I couldn’t find a solution for that I created a simple Rack middleware that rescues the exception and returns the parsing error to the client.
Here’s my gist:
Add it to your Rails app
# application.rb
config.middleware.insert_before ActionDispatch::ParamsParser, 'ParamsParserRescue'
Posted by admin
on December 17, 2012
Today I was confronted with testing my API in Cucumber (I should actually write a post on it). The scenario I was testing was involving deleting a resource that does not belong to this user. As the resource it is not found it raises a ActiveRecord::RecordNotFound error, what is actually ok.
The API client should actually not see the error, but have a 404 returned. I’ve implemented a custom error handling using an error controller and use the routing middlewhere as the “exceptions_app”. More on this can be found here.
Back to my original problem. Everything was working fine. Testing the destroyment using curl was giving me a nice 404 and a “error- not found” JSON response. However Cucumber was raising the error and did not show the error page. I spent some time googling and found a work around. Trying to implement that workaround in env.rb I saw a comment in the env.rb
# By default, any exception happening in your Rails application will bubble up
# to Cucumber so that your scenario will fail. This is a different from how
# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
# exceptions and display an error page (just like when the app is running in production).
# Typical scenarios where you want to do this is when you test your error pages.
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with @allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
So rendering error pages is built in in Cucumber (should have thought about that earlier). It’s as simple as tagging the scenario with @allow-rescue.
Posted by admin
on November 30, 2012
As I am currently working on an application that triggers an event when clicking on a map I needed to implement a test for that.
What I needed was to trigger a mouse click on an exact position on the map.
First you will need to extend cucumber (capybara). Create the click at functionality:
# features/support/mouse_click.rb
Capybara::Node::Element.class_eval do
def click_at(x, y)
wait_until do
right = x - (native.size.width / 2)
top = y - (native.size.height / 2)
driver.browser.action.move_to(native).move_by(right.to_i, top.to_i).click.perform
end
end
end
Then implement the step
And /^I click inside the map to trigger the event$/ do
find("#map").click_at(50, 50)
end
You might need some additional step to make sure the map is loaded, something like this
And /^I wait for the map to appear$/ do
page.should have_xpath("//div[@class='leaflet-map-pane']")
end
Hopes this helps.
Posted by admin
on November 05, 2012
RGeo by default renders spatial columns in WKT. To switch it to GeoJSON, set this in an initializer:
RGeo::ActiveRecord::GeometryMixin.set_json_generator(:geojson)
Posted by admin
on October 30, 2012
If you are running a cucumber scenario and it fails most of the time you need to inspect what’s wrong and you want to look at the page why it does not work as expected.
Usually you would add the step
Then show me the page
Then run it again and look at the page. Wouldn’t it be better to open the page right away after a failing step?
Just add following snippet in an existing step, I have it in a new file support/open_on_failure_steps.rb
After do |scenario|
if scenario.status == :failed
save_and_open_page
end
end
and it will automatically open the failed page for you.