Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module GivenWhenThen
module ClassMethods
def def_Given(name, *args, &block)
_gwt_define(:Given, name, *args, &block)
end
def def_When(name, *args, &block)
_gwt_define(:When, name, *args, &block)
end
def def_Then(name, *args, &block)
_gwt_define(:Then, name, *args, &block)
end
private
def _gwt_define(prefix, name, *args, &block)
define_method("#{prefix} #{name}", *args, &block)
end
end
def self.included(klass)
klass.extend(ClassMethods)
end
def Given(name, *args)
_gwt_call(:Given, name, *args)
end
def When(name, *args)
_gwt_call(:When, name, *args)
end
def Then(name, *args)
_gwt_call(:Then, name, *args)
end
def And(name, *args)
_gwt_call(:And, name, *args)
end
private
def _gwt_call(prefix, name, *args)
if prefix == :And
prefix = @_gwt_last_prefix || :Given
end
public_send("#{prefix} #{name}", *args)
ensure
@_gwt_last_prefix = prefix
end
end
RSpec.configure do |c|
c.include GivenWhenThen, type: :feature
end
@caius

This comment has been minimized.

Copy link
Owner Author

caius commented Apr 19, 2020

it "should check a thing" do
  Given :"there is an existing thing"
  And :"I am logged in as an admin"
  When :"I visit the list of things"
  Then :"I see my thing in the list of things"
  When :"I click edit against my thing"
  And :"I submit an edited thing"
  Then :"I see the updated thing in the list of things"
end

def_Given :"there is an existing thing" do
  @thing = create :thing
end
@ogirginc

This comment has been minimized.

Copy link

ogirginc commented Apr 28, 2020

not terrible, but also probably not a great idea.

It's an amazing idea! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.