Blog

Where to put rspec expectation in Cucumber project? (zagorski software tester)

On March 7, 2015, in Syndicated, by Association for Software Testing
0
credit: cukes.info

TLDR

In this post I will explain how to use rspec expectations in cucumber project that uses page object gem.

In order to be able to use rspec expectations in cucumber project, you first have to include rspec gem in your Gemfile. After that, you have to put in

features/support/env.rb

following line

require ‘rspec/expectations’

You are good to go.

But where I should use rspec matchers, in page class or in step definitions? If you use rspec matcher in page class definition, you will get following exception:

You have to move rspec matchers in step definitions, something like this:

credit: rspec.info

When you think about it, this is logical decision. Page object class should represent page that you interact with with methods that interact with page elements. It should not contain checks of those elements. Step definition contain Then word, so their purpose is to check page elements. For me, that was not obvious so I hope that this post would save you some time.

 

Comments are closed.


Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!