### Execute All Turnip Scenarios with RSpec Source: https://github.com/jnicklas/turnip/wiki/How-to-identify-scenario-using-Location-(or-IDs) This command executes all defined scenarios within the specified feature file using the RSpec runner. Ensure RSpec and Turnip are installed and configured. ```bash $ rspec /path/to/foo.feature ``` -------------------------------- ### Execute Turnip Scenarios by Location with RSpec Source: https://github.com/jnicklas/turnip/wiki/How-to-identify-scenario-using-Location-(or-IDs) This command executes specific scenarios within a feature file by referencing their line numbers. It allows for granular control over which scenarios are run. Ensure RSpec and Turnip are installed. ```bash $ rspec /path/to/foo.feature:1 $ rspec /path/to/foo.feature:2 $ rspec /path/to/feature:3 $ rspec /path/to/feature:6 $ rspec /path/to/feature:7 $ rspec /path/to/feature:16 $ rspec /path/to/feature:24 $ rspec /path/to/feature:100 # (More than 24) ``` -------------------------------- ### Install Turnip Gem Source: https://github.com/jnicklas/turnip/blob/master/README.md Instructions for installing the Turnip gem. This is a prerequisite for using Turnip with RSpec. ```bash gem install turnip ``` -------------------------------- ### Setup Turnip Helper for Rails Projects in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code shows how to set up a `turnip_helper` file for Rails projects. It suggests including `rails_helper` in `turnip_helper` to ensure proper loading of configurations for Turnip tests within a Rails application. ```ruby require 'rails_helper' ``` -------------------------------- ### Execute Turnip Scenarios by ID with RSpec Source: https://github.com/jnicklas/turnip/wiki/How-to-identify-scenario-using-Location-(or-IDs) This command executes specific scenarios within a feature file using their unique IDs, introduced in RSpec 3.3.0. This method provides a stable way to target scenarios even if line numbers change. Ensure RSpec and Turnip are installed. ```bash $ rspec /path/to/foo.feature[1] # All scenarios in the 1st feature $ rspec /path/to/foo.feature[1:2] # The 2nd scenario in the 1st feature $ rspec /path/to/foo.feature[1:4] ``` -------------------------------- ### Example Turnip Feature File Source: https://github.com/jnicklas/turnip/blob/master/README.md A basic Gherkin feature file demonstrating Turnip's syntax for defining features, backgrounds, and scenarios. This file can be placed in the 'spec' directory. ```gherkin # spec/acceptance/attack_monster.feature Feature: Attacking a monster Background: Given there is a monster Scenario: attack the monster When I attack it Then it should die ``` -------------------------------- ### Load Turnip Steps Dynamically in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code demonstrates how to dynamically load Turnip step definition files using `Dir.glob`. This is useful for organizing step definitions in separate directories and loading them automatically. ```ruby Dir.glob("spec/steps/**/*steps.rb") { |f| load f, true } ``` -------------------------------- ### Turnip Step with Alternative Words and Optional Parts Source: https://github.com/jnicklas/turnip/blob/master/README.md Illustrates defining a step that matches variations in wording, including pluralization and optional components. This enhances the flexibility of step definitions. ```ruby step "there is/are :count monster(s)" do |count| @monsters = Array.new(count) { Monster.new } end ``` -------------------------------- ### Simplified Scoped Steps Definition in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code shows a shortcut for defining scoped steps using the `steps_for` helper. It simplifies the process of creating modules and including them with specific tags. ```ruby steps_for :interface do step "I do it" do ... end end ``` -------------------------------- ### Call Steps using `step` method in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code demonstrates calling a step definition directly using the `step` method, mimicking how it would be called from a feature file. This is useful for simplifying complex scenarios or setting up specific states. ```ruby step "the value is :num" do |num| @value = num end step "the value is the magic number" do step "the value is 3" end ``` -------------------------------- ### Call Steps from Other Steps using `send` in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code illustrates how to call one step definition from within another using the `send` method. This is necessary when step descriptions contain spaces or special characters, allowing for step reuse and composition. ```ruby step "the value is :num" do |num| @value = num end step "the value is twice as much as :num" do |num| send "the value is :num", num * 2 end ``` -------------------------------- ### Turnip Step with Placeholder Source: https://github.com/jnicklas/turnip/blob/master/README.md Demonstrates defining a step with a named placeholder ':name' for capturing values from the Gherkin step. This allows for more dynamic step matching. ```ruby step "there is a monster called :name" do |name| @monster = Monster.new(name) end ``` -------------------------------- ### Define Global Turnip Steps Source: https://github.com/jnicklas/turnip/blob/master/README.md Defines steps directly in the global namespace, which Turnip automatically makes available in all features. This is a shortcut for defining globally accessible steps. ```ruby step "there is a monster" do @monster = Monster.new end ``` -------------------------------- ### Global RSpec Before/After Hooks for Features Source: https://github.com/jnicklas/turnip/blob/master/README.md Utilizes RSpec's before and after hooks to execute code before or after all features are run. The 'type' is set to :feature for global application. ```ruby config.before(:type => :feature) do do_something end config.after(:type => :feature) do do_something_else end ``` -------------------------------- ### Use Existing Methods as Steps in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code shows how to designate an existing method as a Turnip step definition. It uses the `step` class method within a module to map a method to a step phrase, making regular Ruby methods callable from feature files. ```ruby module MonsterSteps def create_monster(name) @monster = Monster.new(:name => name) end step :create_monster, "there is a monster called :name" end ``` -------------------------------- ### RSpec Hooks Limited by Tag Source: https://github.com/jnicklas/turnip/blob/master/README.md Applies RSpec before or after hooks to scenarios or features tagged with a specific value. This allows for conditional execution of setup/teardown code. ```ruby config.before(:some_tag => true) do do_something end ``` -------------------------------- ### Define Scoped Steps using Modules and Tags in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code demonstrates how to define scoped step definitions using modules and RSpec metadata. It allows different sets of steps to be included based on scenario tags, preventing naming conflicts. ```ruby module InterfaceSteps step "I do it" do ... end end module DatabaseSteps step "I do it" do ... end end RSpec.configure do |config| config.include InterfaceSteps, :interface => true config.include DatabaseSteps, :database => true end ``` -------------------------------- ### Implement Table Step with Hash Conversion in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby step definition processes a table provided in a feature file. It converts the table into an array of hashes, where each hash represents a row with column headers as keys, suitable for data processing. ```ruby step "there are the following monsters:" do |table| @monsters = {} table.hashes.each do |hash| @monsters[hash['Name']] = hash['Hitpoints'].to_i end end ``` -------------------------------- ### Define Placeholder for 'should'/'should not' in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code defines a custom placeholder named ':whether_to' to handle 'should' and 'should not' conditions in steps. It returns a boolean value based on the matched text, simplifying the creation of expectation steps. ```ruby step 'I :whether_to see :text' do |positive, text| expectation = positive ? :to : :not_to expect(page.body).send expectation, eq(text) end placeholder :whether_to do match /should not/ do false end match /should/ do true end end ``` -------------------------------- ### Define Turnip Steps in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md Shows how to define custom steps for Turnip features using Ruby code. Steps are defined as blocks associated with a step text. ```ruby module MonsterSteps step "there is a monster" do @monster = Monster.new end end ``` -------------------------------- ### Define Multi-Word Regex Placeholder in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby snippet shows how to define a custom placeholder that captures multiple words separated by spaces without surrounding quotes. The regular expression can extract specific parts of the matched phrase. ```ruby placeholder :monster do match /(blue|green|red) (furry|bald) monster/ do |color, hair| Monster.new(color, hair) end end ``` -------------------------------- ### Configure RSpec to Load Turnip Source: https://github.com/jnicklas/turnip/blob/master/README.md Modifies the .rspec file to load the Turnip RSpec integration. This allows RSpec to recognize and process Turnip feature files. ```bash -r turnip/rspec ``` -------------------------------- ### Implement Table Step with Row Conversion in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby step definition iterates through table rows and processes them as arrays of values. It's an alternative to converting the table into hashes, directly using the row's elements for data manipulation. ```ruby step "there are the following monsters:" do |table| @monsters = {} table.rows.each do |(name, hp)| @monsters[name] = hp.to_i end end ``` -------------------------------- ### Include Custom Steps in RSpec Source: https://github.com/jnicklas/turnip/blob/master/README.md Configures RSpec to include custom step definitions defined in a module. This makes the steps available for use in feature files. ```ruby RSpec.configure { |c| c.include MonsterSteps } ``` -------------------------------- ### Define Custom Regex Placeholders in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This snippet demonstrates how to define custom placeholders with regular expressions in Turnip. It allows for matching specific patterns in step text and casting the matched values to appropriate types. Supports multiple matching patterns for a single placeholder. ```ruby step "there are :count monsters" do |count| count.times { Monster.new(name) } end placeholder :count do match /\d+/ do |count| count.to_i end match /no/ do 0 end end ``` -------------------------------- ### Define Default Placeholder without Regex in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby snippet illustrates defining a custom placeholder ':monster_name' using a default block. This approach bypasses regular expression matching and directly uses the provided name to find a corresponding record, likely a database entry. ```ruby placeholder :monster_name do default do |name| Monster.find_by!(name: name) end end ``` -------------------------------- ### Add Turnip to Gemfile Source: https://github.com/jnicklas/turnip/blob/master/README.md Adds the Turnip gem to the test group in a project's Gemfile. This ensures Turnip is available when running tests with Bundler. ```ruby group :test do gem "turnip" end ``` -------------------------------- ### Define Custom RSpec Formatter for Turnip Notifications in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code defines a custom RSpec formatter to listen for Turnip step notifications. It registers itself to receive `step_started`, `step_passed`, `step_failed`, and `step_pending` events, allowing for custom reporting or actions during test execution. ```ruby class MyFormatter RSpec::Core::Formatters.register self, :step_started, :step_passed, :step_failed, :step_pending def step_passed(step) puts "Starting step: #{step.text}" end # … end ``` -------------------------------- ### Integrate Turnip with Capybara in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby snippet shows how to integrate Turnip with Capybara. Requiring 'turnip/capybara' enables the use of Capybara's tags (like @javascript) within Turnip features and sets the `:type => :feature` metadata for Capybara integration. ```ruby require 'turnip/capybara' ``` -------------------------------- ### Configure Turnip Unimplemented Steps Error Handling in Ruby Source: https://github.com/jnicklas/turnip/blob/master/README.md This Ruby code configures RSpec to raise an error for unimplemented steps in Turnip. By default, Turnip marks scenarios as pending; setting `raise_error_for_unimplemented_steps` to `true` will cause them to fail. ```ruby RSpec.configure do |config| config.raise_error_for_unimplemented_steps = true end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.