File: feature_factory.rb

package info (click to toggle)
cucumber 2.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,076 kB
  • sloc: ruby: 17,016; javascript: 4,641; makefile: 12; sh: 10; tcl: 3
file content (67 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
module FeatureFactory
  def create_feature(name = generate_feature_name)
    gherkin = <<-GHERKIN
Feature: #{name}
#{yield}
    GHERKIN
    write_file filename(name), gherkin
  end

  def create_feature_ja(name = generate_feature_name)
    gherkin = <<-GHERKIN
# language: ja
機能: #{name}
#{yield}
    GHERKIN
    write_file filename(name), gherkin
  end

  def create_scenario(name = generate_scenario_name)
    <<-GHERKIN
  Scenario: #{name}
  #{yield}
    GHERKIN
  end

  def create_scenario_ja(name = generate_scenario_name)
    <<-GHERKIN
  シナリオ: #{name}
  #{yield}
    GHERKIN
  end

  def create_step_definition
    write_file generate_step_definition_filename, yield
  end

  def generate_feature_name
    "Test Feature #{next_increment(:feature)}"
  end

  def generate_scenario_name
    "Test Scenario #{next_increment(:scenario)}"
  end

  def next_increment(label)
    @increments ||= {}
    @increments[label] ||= 0
    @increments[label] += 1
  end

  def generate_step_definition_filename
    "features/step_definitions/steps#{next_increment(:step_defs)}.rb"
  end

  def filename(name)
    "features/#{name.downcase.gsub(' ', '_')}.feature"
  end

  def features
    in_current_dir do
      Dir['features/*.feature']
    end
  end
end

World(FeatureFactory)