Giter Club home page Giter Club logo

Comments (2)

elight avatar elight commented on July 18, 2024

For now, the simplest way to do this is to factor your Scenario into a method (yes, you can do this ;-) ) that accept parameters.

For example, it is perfectly legal to do this:

def canned_scenario_with_args(params = {})
  Scenario "My canned senario" do
    Given "A given parameter like #{params[:first_given]}" do
      ....
    end
    When "An event parameter like #{params[:first_when]}" do
      ....
    end
    Then "An expectation parameter like #{params[:first_then]}" do
      ....
    end
  end
end

Want to get whackier? It's perfectly legitimate to pass Procs in Hashes. So, occasionally, I wrote my Coulda tests but inject even more behavior instead of just data. The only downside I find is that the backtrace can become a bit difficult to untangle at times.

def canned_scenario_with_args(params = {})
  Scenario "My canned senario" do
    Given "A given parameter like #{params[:first_given]}" do
      ...
      eval(params[:first_given])
      ...
    end
    When "An event parameter like #{params[:first_when]}" do
      ...
      eval(params[:first_when])
      ...
    end
    Then "An expectation parameter like #{params[:first_then]}" do
      ...
      eval(params[:first_then])
      ...
    end
  end
end

canned_scenario_with_args(
  :first_given => lambda {
    ...
  },
  :first_when => lambda {
    ...
  },
  :first_then => lambda {
    ...
  }
)

To the original point, I'm not averse to using FIT-like tables with Coulda. However, I am hesitant to introduce them into Coulda directly. I prefer an ecology of tools that play well together versus a single monolithic tool that tries to be everything to everyone. I've discussed with a few people, at times, extracting FIT-like table support from Cucumber in such a way that it would be reusable within arbitrary Ruby code including Coulda.

However, adding Scenario Outlines would likely require tighter integration.

from coulda.

elight avatar elight commented on July 18, 2024

FWIW, I've been using Coulda regularly in my consulting. I often extract steps (Given, When, etc.) out into methods that are sometimes reusable across Features. And, yes, I do the same thing within a single Feature as well for Scenarios.

Unlike Cucumber, Coulda is just Ruby. It's important to remember that. You have access to the full Ruby language instead of a coupling of a Turing incomplete programming language (Gherkin) with Ruby.

from coulda.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.