View
Linked contentAuto-destruct in 52 days

Updated: Fixing flaky integration tests

Added a new section on Capybara.default_set_options. The default native fill_in clearing strategy may cause a race-condition (or similar).

Tool 8: Adjust your Capybara configuration

Capybara offers some global variables that can be fine-tuned. If your flickering tests are failing when the fill_in method is used, change the way Capybara clears a field before filling in a new value (Selenium only):

d...

Ruby: A short summary of available hooks in Cucumber

Here is a short summary of Cucumber hooks in Ruby taken from https://github.com/cucumber/cucumber-ruby. Note that the BeforeStep is currently not existing in the Ruby implementation of Cucumber.

Before hooks run before the first step of each scenario.

Before do |scenario|
  ...
end

After hooks run after the last step of each scenario, even when the step result is failed, undefined, pending or skipped.

...

Repeats

Reading an element's attributes with Capybara

capybara_element['attribute_name'] allows accessing an element's attributes in Capybara.

A few examples:

find('#my_element')['class']
# => "first-class second-class"

find('#my_input')['placeholder']
# => "My placeholder value"

find('a#example-link')['href']
# => "http://example.com"

find('#my_element')['missing_attribute']
# => nil

Migrate gem tests from Travis CI to Github Actions with gemika

We currently test most of our gems on Travis CI, but want to migrate those tests to Github Actions. This is a step-by-step guide on how to do this.

Note that this guide requires the gem to use gemika.

  1. Go to a new "ci" branch:
    git checkout -b ci
    
  2. Update gemika to version >= 0.5.0.
  3. Have gemika generate a Github Actions workflow definition by running
    mkdir -p .github/workflows; bundle exec rake gemika:generate_github_actions_workflow > .github/workflows/test.yml
    

...

Repeats

How to fill in multiple lines in a textarea with cucumber

If you want to fill in textareas with multiple lines of text (containing line breaks) you can use Cucumber's docstrings:

And I fill in "Comment" with:

"""
This is a long comment.
With multiple lines.

And paragraphs.
"""

The step definition is part of the spreewald gem

Auto-destruct in 32 days

Geordi 4.2.0 released

We released a new version of our gem geordi

4.2.0 2020-10-02

Compatible changes

  • Add auto_update_chromedriver as global setting option to automatically update chromedriver before cucumber
    tests, if Chrome and chromedriver versions don't match.
  • Dump command: Add support for multiple databases
  • Add Ruby 2.7 to list of supported Ruby versions
  • Fix #115: geordi cucumber --modified command, that corrupted filenames like:
    No such file or directory tures/pages.feature
    
  • Avoi...
Auto-destruct in 32 days

Spreewald 2.9, 2.99 and 3.0.0 released

Versions 2.9.0, 2.99.0 and 3.0.0 of our gem Spreewald have been released.

2.9.0: Rework email steps

  • The step an email should have been sent with: does now support wildcards (* at the end of a line to ignore the rest of the line, * as single character in a line to ignore multiple lines). The step also has better error messages if an email could not be found.
  • The step show me the emails got an option to display only the email headers. Additionally, a new step `show me the email( header)?s...
Repeats

Cucumber step to match table rows with Capybara

These steps are now part of Spreewald.

This note describes a Cucumber step that lets you write this:

Then I should see a table with the following rows:
  | Bruce Wayne       | Employee    | 1972 |
  | Harleen Quinzel   | HR          | 1982 |
  | Alfred Pennyworth | Engineering | 1943 |

If there are additional columns or rows in the table that are not explicitely expected, the step won't complain. It does however expect the rows to be ordered as stat...

Auto-destruct in 31 days

Cucumber Factory 2.3.0 and 2.3.1 released

Versions 2.3.0 and 2.3.1 of our gem Cucumber Factory have been released.

2.3.0

  • Added a step to add file objects to a model:
    Given there is a user with the avatar file:"path/to/avatar.jpg"
    
    Both single and double quotes are supported.

2.3.1

  • Lowered the priority of all steps in this gem to avoid issues with overlapping steps.

VCR and the webdrivers gem

If you're using the webdrivers gem and VCR together, depending on your configuration, VCR will yell at you regulary.
The webdrivers gem tries to update your webdrivers on your local machine. To do so, it checks the internet for newer versions, firing an HTTP-request to e.g. https://chromedriver.storage.googleapis.com

You can "fix" this in multiple ways:

  1. Update your drivers on your machine with
    RAILS_ENV=test rake webdrivers:chromedriver:update

  2. Ignore the driver update-URL in your ...

Auto-destruct in 23 days

Cucumber Factory 2.2.0 released

Version 2.2.0 of our gem Cucumber Factory has been released.

  • A step was added that allows modifying existing records with a similar syntax to creating new records:
    (Given "Bob" is a user)
      And "Bob" has the email "foo@bar.com" and is subscribed
    
    • This step will also work with doc strings or tables:
    (Given "Bob" is a user)
      And the user above has these attributes:
      | name  | Bob         |
      | email | foo@bar.com | 
    

Carrierwave: How to migrate to another folder structure

A flat folder structure can be cool if you have only a few folders but can be painful for huge amounts. We recently had this issue in a project with more than 100.000 attachments, where we used a structure like this /attachments/123456789/file.pdf.

Even the ls command lasted several minutes to show us the content of the attachments folder.

So we decided to use a more hierarchical structure with a limited maximum of folder per layer. As our attachment folder will grow very fast we choosed to use three layers, but that's up to you. Here...

Linked contentRepeats

Jasmine: Adding custom matchers

Definition

A matcher is a function that returns an object with a compare key. Usually it is registered with beforeEach:

beforeEach ->
  jasmine.addMatchers
  
    # Example matcher
    toBeAnything: ->
      compare: (actualValue, matcherArguments...) ->
         # Do some computations here ...
         
         # Return whether the actualValue matches the expectation
         pass: true

Usage

expect(actualValue).toBeAnything(matcherArguments...)

When a matcher is invoked, Jasmine will call its compare() fu...

Cucumber 4 and VCR integration

If you are trying to integrate VCR and Cucumber 4 and you're using the use_scenario_name: true option you will run into an error like this:

undefined method `feature' for #<Cucumber::RunningTestCase::TestCase:0x00005650550ba080>

Currently the VCR integration and Cucumber 4 is broken, but you can find an open issue with details and a monkey patch here.

Repeats

Selenium: How to debug the communication with the Webdriver API

Selenium allows you to log all requests to the Webdriver API. Therefore add the following line to e.g. features/support/selenium.rb:

Selenium::WebDriver.logger.level = :debug

If you want to see the output of the driver itself, here is an example on how to enable Chromedriver logging.

Example output

When you run a command like bundle exec cucumber --format=pretty features/some.feature you will see the API communication before the step is printed (here you see the log for the step And I press "Save").

...

Parallel cucumber: How to pass in cucumber arguments

Here is an example with the --tags option. You need to wrap them inside --cucumber-options option of parallel_cucumber.

DISPLAY=:17 bundle exec parallel_cucumber --cucumber-options '--tags @solo' features

See more details in the docs.

Linked content

The State of Ruby 3 Typing | Square Corner Blog

We're pleased to announce Ruby 3’s new language for type signatures, RBS. One of the long-stated goals for Ruby 3 has been to add type checking tooling. After much discussion with Matz and the Ruby committer team, we decided to take the incremental step of adding a foundational type signature language called “RBS,” which will ship with Ruby 3 along with signatures for the stdlib. RBS command line tooling will also ship with Ruby 3, so you can generate signatures for your own Ruby code.

Ruby 3 is coming, and it will have optional type sign...

Linked content

FactoryBot: Traits for enums

FactoryBot allows to create traits from Enums since version 6.0.0

The automatic definition of traits for Active Record enum attributes is enabled by default, for non-Active Record enums you can use the traits_for_enum method.

Example

factory :user do
  traits_for_enum :role, %w[admin contact] # you can use User::ROLES here, of course
end

is equivalent to

factory :user do
  trait :admin do
    role { 'admin' }
  end

  trait :contact do
    role { 'c...
This website uses short-lived cookies to improve usability.
Accept or learn more