module Yari::DSL::Rspec

Public Instance Methods

background(&block) click to toggle source
# File lib/yari/yari_dsl.rb, line 50
def background(&block)
  before(:each, &block)
end
scenario(name = nil, new_metadata = {}, &block) click to toggle source
# File lib/yari/yari_dsl.rb, line 54
def scenario(name = nil, new_metadata = {}, &block)
  raise ArgumentError.new("requires a name") if name.nil?

  matching_scenario = find_scenario(self.metadata[:current_feature], name)
  new_metadata[:scenario_name]= name

  if matching_scenario
    if matching_scenario.tags.include?('@updated')
      pending_scenario(name, new_metadata, block.source_location,
                       "Scenario has been marked as updated\n \t# Update specs for this scenario and remove the @updated tag\n \t# Feature file: '#{feature_path(block.source_location)}'"
      )
    # elsif matching_scenario.arguments
    #   specify "Scenario: #{name}", new_metadata do
    #     instance_exec(*matching_scenario.arguments, &block)
    #   end
    else
      specify("Scenario: #{name}", new_metadata, &block)
    end
  else
    pending_scenario(name, new_metadata, block.source_location, "No such scenario in '#{feature_path(block.source_location)}'")
  end
end
scenario_with_test_cases(name = nil, new_metadata = {}, &block) click to toggle source
# File lib/yari/yari_dsl.rb, line 78
def scenario_with_test_cases(name = nil, new_metadata = {}, &block)
  raise ArgumentError.new("requires a name") if name.nil?

  matching_scenario = find_scenario(self.metadata[:current_feature], name)

  if matching_scenario
    if matching_scenario.tags.include?('@updated')
      pending_scenario(name, new_metadata, block.source_location,
                       "Scenario has been marked as updated\n \t# Update specs for this scenario and remove the @updated tag\n \t# Feature file: '#{feature_path(block.source_location)}'"
      )
    else
      describe("Scenario: #{name}", new_metadata.merge(:scenario_name => name), &block)
    end
  else
    pending_scenario(name, new_metadata, block.source_location, "No such scenario in '#{feature_path(block.source_location)}'")
  end
end
test_case(name = nil, new_metadata = {}, &block) click to toggle source
# File lib/yari/yari_dsl.rb, line 96
def test_case(name = nil, new_metadata = {}, &block)
  raise ArgumentError.new("requires a name") if name.nil?
  new_metadata[:test_case_name]= name
  specify("Test_Case: #{name}", new_metadata, &block)
end

Private Instance Methods

feature_path(spec_location) click to toggle source
# File lib/yari/yari_dsl.rb, line 110
def feature_path(spec_location)
  Yari.spec_to_feature(spec_location.first, false)
end
find_scenario(feature, name) click to toggle source
# File lib/yari/yari_dsl.rb, line 104
def find_scenario(feature, name)
  feature.scenarios.find do |scenario|
    scenario.name == name
  end
end
pending_scenario(name, new_metadata, spec_location, reason) click to toggle source
# File lib/yari/yari_dsl.rb, line 114
def pending_scenario(name, new_metadata, spec_location, reason)
  specify name, new_metadata do |example|
    example.metadata.merge!(
        full_description: "Scenario: #{name}",
        location: "#{spec_location[0]}:#{spec_location[1]}"
    )
    skip reason
  end
end