View

How to use triple quotes inside a Cucumber docstring

Cucumber's docstrings let you add long strings to a step like this:

# foo.feature
Given this text:
"""
First line
Second line

Second Paragraph
"""

# foo_steps.rb
Given /^this text:$/ |docstring|
  puts docstring.split
end

You see these neat triple double quotes ("""). Now what to do when you need your docstring to contain triple double quotes, too?

# Does not work:
Given this text:
"""
Docstrings work like this:
  """
  Docstring example
  """
You see?
"""

Update: Official solution

You can escape the inner quotes …

Test e-mail dispatch in Cucumber

Spreewald has steps that let you test that e-mails have been sent, using arbitrary conditions in any combination.

The attached file is for legacy purposes only.

How to fix routing error when using concerns in Rails up to 3.2.22.1

tl;dr

  • Don't write resources :people, :concerns => :trashable
  • Write

    resources :people do
      concerns :trashable
    end
    

Why

Writing a controller spec I encountered this error:

Failure/Error: get :index
ActionController::RoutingError:
  No route matches {:controller=>"people"}

caused by this route definition

resources :people, :concerns => :trashable

which renders strange routes:

```
trash_person PUT /people/:id/trash(.:format) people#check {:concerns=>:trashable}

Find the innermost DOM element that contains a given string

Let's say you want to find the element with the text hello in the following DOM tree:

<html>
  <body>
    <article>
      <strong>hello</strong>
      <strong>world</strong>
    </article>
  </body>
</html>

You might think of using jQuery's :contains selector:

$(":contains('hello')")

Unfortunately that returns a lot more elements than you expect:

[ <html>...<html>,
  <body>...</body>,
  <article>...</article>,
  <strong>hello</strong> ]

The reason for this is that…

Geordi 1.3 released

Changes:

  • Geordi is now (partially) tested with Cucumber. Yay!
  • geordi cucumber supports a new @solo tag. Scenarios tagged with @solo will be excluded from parallel runs, and run sequentially in a second run
  • Support for Capistrano 2 AND 3 (will deploy without :migrations on Capistrano 3)
  • Now requires a .firefox-version file to set up a test firefox. By default now uses the system Firefox/a test Chrome/whatever and doesn't print warnings any more.
  • geordi deploy --no-migrations (aliased -M): Deploy with `cap …
Linked content

Geordi 1.2 released

Changes:

  • Remove some old binaries (commands still exist in geordi) and mark others as deprecated
  • Rewrite deploy command to support most deploy scenarios:
    • master to production
    • feature branch to staging
    • master to staging or production to production (plain deploy)
  • Improve Cucumber command (fixes #18):
    • Fix pass-through of unknown options to Cucumber
    • Add –rerun=N option to rerun failed Cucumber tests up to N times. Reboots the test environment between runs, thus will pick up fixes you made durin…

How to open a new tab with Selenium

Until recently, you could open a new tab via window.open when using execute_script in Selenium tests. It no longer works in Chrome (will show a "popup blocked" notification).

This is because browsers usually block window.open unless the user interacted with an element for security reasons. I am not sure why it did work via Selenium before.

Here is an approach that will insert a link into the page, and have Selenium click it:

path = "/your/path/here"
id = "helper_#{SecureRandom.hex(8)}"
execute_script <<-JAVASCRIPT
  ...

Make nokogiri >=1.6.0 use system libxml2

Quick check: bin/rails runner 'puts Nokogiri::VersionInfo.new.libxml2_using_system?'

Step by step instruction

Nokogiri uses vendored libxml2 since version 1.6.0, which means that each time a new issue with libxml2 occurs, you have to update nokogiri itself. Another approach is to use the system lib again, as it patches the libxml2 library with periodically system updates.

  1. bundle config --local build.nokogiri --use-system-libraries
  2. Ensure that .bundle is not gitignored and .bundle/config contains these lines:

``` …

Linked content

RSpec & Devise: How to sign in users in request specs

You know that Devise offers RSpec test helpers for controller specs. However, in request specs, they will not work.

Here is a solution for request specs, adapted from the Devise wiki. We will simply use Warden's test helpers – you probably already load them for your Cucumber tests.

First, we define sign_in and sign_out methods. These will behave just like …

Geordi: Running headless Selenium tests

Geordi now supports our solution for running Selenium tests without having Firefox windows popping up all over your workspace.

This will stop Selenium windows from appearing on your desktop, but you can still inspect them when necessary.

Installation

Update geordi with gem install geordi.

Run geordi vnc --setup and follow the instructions.

Usage

geordi cucumber will automatically use VNC. Launchy will still open pages in the usual place.

geordi vnc will allow you to in…

You can now override all Spreewald steps with more specific versions

You can now define this step without Cucumber raising Cucumber::Ambiguous:

Then /^I should see "whatever I want"$/ do
  ...
end

This is available in Spreewald 1.5.0+.

Override Cucumber steps without an ambiguity error

Cucumber raises a Cucumber::Ambiguous if more than one step definitions match a step.

Our new cucumber_priority gem provides a way to mark step definitions as overridable, meaning that they can always be overshadowed by a more specific version without raising an error.

This gem is currently used by spreewald and cucumber_factory.

Marking step definiti…

Spreewald: Click on an element with a CSS selector

Spreewald 1.4.0 comes with this step:

When I click on the element ".sidebar"

We recommend to define a selector_for method in features/support/selectors.rb so you can refer to the selector in plain English:

When I click on the element for the sidebar
Repeats

How to: Start Selenium browser maximized or with custom window size

If your application requires a minimum window size (like 1024 pixels wide) and/or you have tests failing because elements are out of reach and can't be clicked, you may want to set a specific size for your browser window.

Put the following code somewhere inside features/support (e.g. env.rb) to resize your browser window for any scenario tagged @javascript.

Before '@javascript' do
  page.driver.browser.manage.window.resize_to(1024, 768)
end

If this does not work, try using Capybara.current_session instead of page:

`…

Linked content

natritmeyer/site_prism

SitePrism gives you a simple, clean and semantic DSL for describing your site using the Page Object Model pattern, for use with Capybara in automated acceptance testing.

The Page Object Model is a test automation pattern that aims to create an abstraction of your site's user interface that can be used in tests. The most common way to do this is to model each page as a class, and to then use instances of those classes in your tests.

If a class represents a page then each element of the page is represented by a method that, when cal…

List of Helpful RubyMine Shortcuts

CTRL + SHIFT + ALT + N
Search for any symbol in your application, like CSS classes, Ruby classes, methods, helpers etc.
CTRL + SHIFT + N
Search for filename in your application (also dependencies)
CTRL + E
Open a list of recently opened files
ALT + POS1
Open a the navigation bar as a context menu. Allows you to quickly navigate between files.

Actions

CTRL + SHIFT + A
Find and execute a menu actio…

Spreewald 1.2.11 fixes frequent "no alert open" errors on Chrome

When running capybara with Chrome you might start seeing frequent "no alert open" errors when trying to interact with browser dialogs. This seems to be triggered by a recent Chrome update.

Apparently these dialogs no longer appear instantly. Spreewald 1.2.11 fixes the "When I confirm the browser dialog" and similar steps by waiting for the dialog to appear.

FactoryGirl: How to easily create users with first and last name

In most of our applications, users have their first and last name stored in separate columns. However, specifying them separately quickly gets annoying, especially when proxying them from cucumber_factory:

Given there is a user with the first name "Dominik" and the last name "Schöler"

Wouldn't it be nice if you could just say:

Given there is a user with the name "Dominik Schöler"

and have FactoryGirl assign first and last name automatically? The code below achieves that!

##…

This website uses cookies to improve usability and analyze traffic.
Accept or learn more