How to Integrate Cucumber Tests with Rails Event Store

May 07, 2019
3 min read
 How to Integrate Cucumber Tests with Rails Event Store - Cover photo
1. Introduction
This is a short tutorial on how to integrate cucumber tests with Rails Event Store
The gem for Event Store is "rails_event_store", which can be found here and for cucumber, it is "cucumber-rails", and can be found here
2.How to integrate Cucumber Tests with Rails Event Store

In order to demonstrate this, I’ve created a demo application that stores and saves data about an item, starting with its creation, the changes of its properties and its deletion. To do this, we have a file called events.rb where all these events are defined.

Let's start by adding the required gems inside Gemfile: rails_event_store, cucumber-rails, and rails_event_store-rspec, which is the gem used by Event Store for testing. Now we can run bundle so we can use them. 
  gem 'cucumber-rails', require: false
  gem 'database_cleaner'
  
  gem 'rails_event_store-rspec'
The rails_event_store_rspec gem provides some matchers such as have_published or  be_event, which can easily be used to ensure that the events are published correctly.
The next step is to include RailsEventStore::RSpec::Matchers into the cucumber setup file so we can access the matchers. We can also add a method inside this file, which we can call event_store, and which can be used to skip the call to Rails.configuration.event_store each time inside step definitions.
require 'cucumber/rails'

include ::RailsEventStore::RSpec::Matchers

def event_store
  Rails.configuration.event_store
end
The events registered inside events.rb are: ItemCreated, ItemUpdated and ItemDeleted that correspond to the three main states that an item can go through.
module Events
  ItemCreated = Class.new(RailsEventStore::Event)
  ItemUpdated = Class.new(RailsEventStore::Event)
  ItemDeleted = Class.new(RailsEventStore::Event)
end
Now that we have defined the events, we can create the step definition file and .feature file in order to test whether our events have been correctly published.
First, let’s add some data to an item. In our case, the uid and the name.
When an event is published, we can use the have_published method to check if the event was published once and if it was published on the right stream.
We can also check the number of events published for a specific stream.
Given("uid {int} and name {string}") do |uid, name|
  @data = { uid: uid, name: name }
end

When("{string} event is published") do |event|
  stream_name = "Item$#{@data[:uid]}"

  event = event_type(event).new(data: @data)
  event_store.publish(event, stream_name: stream_name)
end

Then("an {string} event should be published once for item {int}") do |event, uid|
  expect(event_store).to have_published(
    an_event(event_type(event))).in_stream("Item$#{uid}").once
end

Then("there should be {int} events published for item stream {string}") do | event_numbers, stream_name|
  expect(event_store.read.stream(stream_name).to_a.count).to eq event_numbers
end

def event_type(event)
  "Events::#{event}".constantize
end
Feature: The system tracks items as they go through different states
  Scenario: Check if ItemCreated event is published
            Given uid 1 and name "item_1"
            When "ItemCreated" event is published
            Then an "ItemCreated" event should be published once for item 1

  Scenario: Check if ItemUpdated event is published
            Given uid 2 and name "item_2"
            When "ItemUpdated" event is published
            Then an "ItemUpdated" event should be published once for item 2

  Scenario: Check the number of events published by an item
            Given uid 3 and name "item_3"
            When "ItemCreated" event is published
              And "ItemUpdated" event is published
              And "ItemDeleted" event is published
            Then there should be 3 events published for item stream "Item$3"

3. Conclusion
In this snippet, I tried to implement some basic examples that demonstrate the integration of Rails Event Store and cucumber tests, but these examples can be extended and improved. 
The entire implementation can be found on GitHub on this repository. You can also view the documentation for rails_event_store-rspechere.

Share on:

Want to stay on top of everything?

Get updates on industry developments and the software solutions we can now create for a smooth digital transformation.

* I read and understood the ASSIST Software website's terms of use and privacy policy.

Frequently Asked Questions

1. What is ASSIST Software's development process?  

The Software Development Life Cycle (SDLC) we employ defines the following stages for a software project. Our SDLC phases include planning, requirement gathering, product design, development, testing, deployment, and maintenance.

2. What software development methodology does ASSIST Software use?  

ASSIST Software primarily leverages Agile principles for flexibility and adaptability. This means we break down projects into smaller, manageable sprints, allowing continuous feedback and iteration throughout the development cycle. We also incorporate elements from other methodologies to increase efficiency as needed. For example, we use Scrum for project roles and collaboration, and Kanban boards to see workflow and manage tasks. As per the Waterfall approach, we emphasize precise planning and documentation during the initial stages.

3. I'm considering a custom application. Should I focus on a desktop, mobile or web app?  

We can offer software consultancy services to determine the type of software you need based on your specific requirements. Please explore what type of app development would suit your custom build product.   

  • A web application runs on a web browser and is accessible from any device with an internet connection. (e.g., online store, social media platform)   
  • Mobile app developers design applications mainly for smartphones and tablets, such as games and productivity tools. However, they can be extended to other devices, such as smartwatches.    
  • Desktop applications are installed directly on a computer (e.g., photo editing software, word processors).   
  • Enterprise software manages complex business functions within an organization (e.g., Customer Relationship Management (CRM), Enterprise Resource Planning (ERP)).

4. My software product is complex. Are you familiar with the Scaled Agile methodology?

We have been in the software engineering industry for 30 years. During this time, we have worked on bespoke software that needed creative thinking, innovation, and customized solutions. 

Scaled Agile refers to frameworks and practices that help large organizations adopt Agile methodologies. Traditional Agile is designed for small, self-organizing teams. Scaled Agile addresses the challenges of implementing Agile across multiple teams working on complex projects.  

SAFe provides a structured approach for aligning teams, coordinating work, and delivering value at scale. It focuses on collaboration, communication, and continuous delivery for optimal custom software development services. 

5. How do I choose the best collaboration model with ASSIST Software?  

We offer flexible models. Think about your project and see which models would be right for you.   

  • Dedicated Team: Ideal for complex, long-term projects requiring high continuity and collaboration.   
  • Team Augmentation: Perfect for short-term projects or existing teams needing additional expertise.   
  • Project-Based Model: Best for well-defined projects with clear deliverables and a fixed budget.   

Contact us to discuss the advantages and disadvantages of each model. 

ASSIST Software Team Members

See the past, present and future of tech through the eyes of an experienced Romanian custom software company. The ASSIST Insider newsletter highlights your path to digital transformation.

* I read and understood the ASSIST Software website's terms of use and privacy policy.

Follow us

© 2025 ASSIST Software. All rights reserved. Designed with love.