run guard cucumber features if (and only if) guard rspec passes

222 views
Skip to first unread message

Brandon Faloona

unread,
Oct 30, 2012, 9:32:15 PM10/30/12
to guar...@googlegroups.com
Greetings-

I have rspec and cucumber guards in my Guardfile but I'd like to run cucumber features if (and only if) my rspec tests ALL pass. Is that possible?


Michael Kessler

unread,
Oct 31, 2012, 2:47:07 AM10/31/12
to guar...@googlegroups.com
Hi

It's not supported out of the box, but you can achieve it by using callbacks.

guard :rspec do

# Trigger all Cucumber features when all Specs passed
callback(:all_end) do
unless Guard.guards(:rspec).instance_variable_get('@last_failed')
Guard.run_all({ :guard => Guard.guards(:cucumber) })
end
end
end

@thibaudgg: Would be nice to have an accessor for `@last_failed` :P

Michael

Thibaud Guillaume-Gentil

unread,
Oct 31, 2012, 3:34:26 AM10/31/12
to guar...@googlegroups.com
Good point @netzpirat, I added an accessor for last_failed & failed_paths in guard-rspec release 2.1.1.

Thanks!

Thibaud

Jared Moody

unread,
Nov 7, 2012, 3:03:43 PM11/7/12
to guar...@googlegroups.com
Isn't the hook :run_all_end? I think this little snipped would be a good candidate for a wiki page; since this is how autospec works, I was looking for a way to make it the same.

Rémy Coutable

unread,
Nov 7, 2012, 3:13:08 PM11/7/12
to guar...@googlegroups.com
Yep it's :run_all_end, good catch!

Feel free to create a Wiki page for that!

Rémy

Jared Moody

unread,
Nov 7, 2012, 9:18:58 PM11/7/12
to guar...@googlegroups.com
I was thinking this should go on the guard-cucumber github wiki, but it doesn't look like wiki pages are enabled.

Jared Moody

unread,
Nov 7, 2012, 9:24:48 PM11/7/12
to guar...@googlegroups.com
er, maybe just I'm not a contributor

Rémy Coutable

unread,
Apr 16, 2013, 3:36:10 PM4/16/13
to guar...@googlegroups.com
Hi,

Just wanted to let you know that there's actually a useful feature (not documented in the README but in Rubydoc.info: http://rubydoc.info/gems/guard/Guard/Group) in Guard that allows you to halt Guard plugins execution inside a group if one of the plugins throws :task_has_failed. Each Guard plugins has to implement this but luckily for you guard-rspec does implement it: https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec.rb#L40

To take advantage of this feature, simple put your rspec and your cucumber plugins in the same group and set the :halt_on_fail group option to true.

Like this:

group :specs, halt_on_fail: true do

  guard :rspec do
    watch(...)
  end

  guard :cucumber do
    watch(...)
  end

end

I think in your case, you'll have to set a "watch" that run all the cucumber specs everytime (and it'll actually run only when the specs pass).

Hope that helps!

Regards,
Rémy
Reply all
Reply to author
Forward
0 new messages