[LRUG] Writing readable feature tests with RSpec

Andrew Premdas apremdas at gmail.com
Fri Jul 25 17:24:39 PDT 2014


On 25 July 2014 11:46, Murray Steele <murray.steele at gmail.com> wrote:

> I really liked that article because it matches how I write rspec features
> :)
>
> I like cucumber because of how it makes me think about what the user
> journey I’m testing is actually about and for, but I dislike cucumber
> because I think the regexp matching for step definitions places an
> unnecessary burden on the developer.
>

This is really unfortunate. The fact that regex's are there in Cucumber
means that you 'can' do all sorts of stupid things with them. If you do
that will be a burden. However it doesn't mean you should do this or have
to do this. 50% of my step definitions have no parameters at all, and I
suspect less than 3% have more then one parameter.

We don't criticize Ruby for allowing us to write stupid code, but it seems
that we expect Cucumber to do more.


>
> But I find that I write very cucumber-ish rspec features.  I’ll have a bit
> of “As a… I want to… In order to…” as the name of the feature and then my
> scenario names will be a imperative style “given…when…then…” describing
> what’s going on.  The actual body of the scenario will be a bunch of very
> high-level method calls like “login_as_a_whatever_user”, “create_a_blah”,
> “search_for_something”, “check_that_widget_appears_in_the_place”.
>
> I try to keep raw capybara calls out of the scenario body and only use it
> in those methods.  I’m not totally strict about that, I might allow myself
> a visit “/some/path” or click_on ‘some label’ as I think they’re pretty
> readable.  I also find that I’m not that interested in reuse of these
> methods.  I might extract some common helpers for dealing with login or
> dealing with common UI patterns, but mostly the methods live at the bottom
> of the feature file they’re used in.
>
> I think this gives me the same thoughtfulness and readability of a
> cucumber feature, but without the context switch of dealing with gherkin,
> step_definitions and World(all the helpers).
>
>
> On 25 July 2014 10:26, Joel Chippindale <joel.chippindale at futurelearn.com>
> wrote:
>
>> We recently blogged about how, at FutureLearn, we write readable feature
>> tests with RSpec*, see
>> https://about.futurelearn.com/blog/how-we-write-readable-feature-tests-with-rspec/,
>> and it made me wonder how common this approach was.
>>
>> Are any of you using this approach already? If so, how are you finding it?
>>
>> J.
>>
>>
>> * Hat tip to the developers at Econsultancy who introduced me to this way
>> of using RSpec.
>>
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
>> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
>> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>
>>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>


-- 
------------------------
Andrew Premdas
blog.andrew.premdas.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140726/a7fc2105/attachment-0003.html>


More information about the Chat mailing list