maniok_bdd 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,19 +1,25 @@
1
1
  BDD with POROs
2
2
 
3
- [![Build Status](https://travis-ci.org/21croissants/maniok_bdd.png?branch=master)](https://travis-ci.org/21croissants/maniok_bdd) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/21croissants/maniok_bdd) [![Dependency Status](https://gemnasium.com/21croissants/maniok_bdd.png)](https://gemnasium.com/21croissants/maniok_bdd)
3
+ [![Gem Version](https://badge.fury.io/rb/maniok_bdd.png)](http://badge.fury.io/rb/maniok_bdd)
4
+ [![Dependency Status](https://gemnasium.com/21croissants/maniok_bdd.png)](https://gemnasium.com/21croissants/maniok_bdd)
5
+ [![Build Status](https://travis-ci.org/21croissants/maniok_bdd.png?branch=master)](https://travis-ci.org/21croissants/maniok_bdd)
6
+ [![Coverage Status](https://coveralls.io/repos/21croissants/maniok_bdd/badge.png?branch=master)](https://coveralls.io/r/21croissants/maniok_bdd)
7
+ [![Code Climate](https://codeclimate.com/github/21croissants/maniok_bdd.png)](https://codeclimate.com/github/21croissants/maniok_bdd)
4
8
 
5
- Install
6
- =======
9
+ # Documentation
10
+
11
+ [Hosted on relish](https://www.relishapp.com/21croissants/maniok-bdd)
12
+
13
+ # Install
7
14
 
8
15
  gem install maniok_bdd
9
16
 
10
- Usage
11
- =====
17
+ # Usage
12
18
 
13
19
  CODE EXAMPLE
14
20
 
15
- Author
16
- ======
21
+ # Author
22
+
17
23
  [Jean-Michel Garnier](http://21croissants.com)<br/>
18
24
 
19
25
  License: MIT<br/>
@@ -0,0 +1,36 @@
1
+ class ManiokBdd::Cli
2
+
3
+ def initialize(args)
4
+ @feature_file = args.first
5
+ end
6
+
7
+ def run
8
+ gherkin_formatter = ManiokBdd::GherkinFormatter.build @feature_file
9
+
10
+ create_spec_acceptance_folder
11
+ write_file ruby_file, gherkin_formatter.to_s
12
+
13
+ 0 # success:)
14
+ end
15
+
16
+ def create_spec_acceptance_folder
17
+ create_unless_exists "spec"
18
+ create_unless_exists File.join("spec", "acceptance")
19
+ end
20
+
21
+ def ruby_file
22
+ feature_file_basename = File.basename(@feature_file)
23
+ File.join "spec", "acceptance", "#{feature_file_basename}.rb"
24
+ end
25
+
26
+ private
27
+
28
+ def write_file(file_path, content)
29
+ open(file_path, 'w') { |f| f << content }
30
+ end
31
+
32
+ def create_unless_exists(path)
33
+ Dir.mkdir(path) unless Dir.exist?(path)
34
+ end
35
+
36
+ end
@@ -0,0 +1,101 @@
1
+ require 'gherkin/parser/parser'
2
+
3
+ class ManiokBdd::GherkinFormatter
4
+
5
+ def self.build(feature_file)
6
+ new.tap do |gherkin_formatter|
7
+ parser = Gherkin::Parser::Parser.new(gherkin_formatter, true)
8
+ parser.parse(File.read(feature_file), feature_file, 0)
9
+ end
10
+ end
11
+
12
+ def to_s
13
+ @feature.to_s
14
+ end
15
+
16
+ def feature(gherkin_model_feature)
17
+ @feature = Feature.new gherkin_model_feature
18
+ end
19
+
20
+ class Feature
21
+ attr_reader :scenarios
22
+
23
+ def initialize(gherkin_model_feature)
24
+ @gherkin_model_feature = gherkin_model_feature
25
+ @scenarios = []
26
+ end
27
+
28
+ def to_s
29
+ # TODO later
30
+ #{@gherkin_model_feature.description}
31
+
32
+ <<RUBY_FEATURE
33
+ require 'spec_helper'
34
+
35
+ Feature "#{@gherkin_model_feature.name}" do
36
+
37
+ #{print_scenarios}
38
+ end
39
+ RUBY_FEATURE
40
+ end
41
+
42
+ def print_scenarios
43
+ @scenarios.map do |scenario|
44
+ scenario.to_s
45
+ end.join("\n")
46
+ end
47
+ end
48
+
49
+ def scenario(gherkin_model_scenario)
50
+ @feature.scenarios << (@current_scenario = Scenario.new(gherkin_model_scenario))
51
+ end
52
+
53
+ class Scenario
54
+ attr_reader :steps
55
+ def initialize(gherkin_model_scenario)
56
+ @gherkin_model_scenario = gherkin_model_scenario
57
+ @steps = []
58
+ end
59
+
60
+ def to_s
61
+ <<RUBY_SCENARIO
62
+ Scenario "#{@gherkin_model_scenario.name}" do
63
+
64
+ #{print_steps}
65
+ end
66
+ RUBY_SCENARIO
67
+ end
68
+
69
+ def print_steps
70
+ @steps.map do |step|
71
+ step.to_s
72
+ end.join("\n")
73
+ end
74
+ end
75
+
76
+ def step(gherkin_model_step)
77
+ @current_scenario.steps << Step.new(gherkin_model_step)
78
+ end
79
+
80
+ class Step
81
+ def initialize(gherkin_model_step)
82
+ @gherkin_model_step = gherkin_model_step
83
+ end
84
+
85
+ def to_s
86
+ <<RUBY_STEP
87
+ #{@gherkin_model_step.keyword}"#{@gherkin_model_step.name}" do
88
+
89
+ end
90
+ RUBY_STEP
91
+ end
92
+ end
93
+
94
+ # to avoid undefined method `uri' & efo and keep Gherkin parser happy
95
+ def uri(*)
96
+ end
97
+
98
+ def eof
99
+ end
100
+
101
+ end
@@ -0,0 +1,17 @@
1
+ module ManiokBdd::RSpec
2
+ module BaseFormatter
3
+ def example_step_started(example, type, message, options)
4
+ end
5
+
6
+ def example_step_passed(example, type, message, options)
7
+ end
8
+
9
+ def example_step_pending(example, type, message, options)
10
+ end
11
+
12
+ def example_step_failed(example, type, message, options)
13
+ end
14
+ end
15
+ end
16
+
17
+ RSpec::Core::Formatters::BaseFormatter.send :include, ManiokBdd::RSpec::BaseFormatter
@@ -0,0 +1,54 @@
1
+ module ManiokBdd::RSpec
2
+ module DocumentationFormatter
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include InstanceMethods
6
+
7
+ alias :example_started_without_steps :example_started
8
+ alias :example_started :example_started_with_steps
9
+
10
+ alias :example_passed_without_steps :example_passed
11
+ alias :example_passed :example_passed_with_steps
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def example_started_with_steps(example)
17
+ example_started_without_steps(example)
18
+
19
+ if example.options[:with_steps]
20
+ full_message = "#{current_indentation}#{example.description}"
21
+ output.puts white(full_message)
22
+ end
23
+ end
24
+
25
+ def example_passed_with_steps(example)
26
+ example_passed_without_steps(example) unless example.options[:with_steps]
27
+ end
28
+
29
+ def example_step_passed(example_group, type, message, options)
30
+ full_message = "#{current_indentation} #{type.to_s.capitalize} #{message}"
31
+ output.puts green(full_message)
32
+ end
33
+
34
+ def example_step_pending(example_group, type, message, options)
35
+ full_message = "#{current_indentation} #{type.to_s.capitalize} #{message}"
36
+
37
+ if options[:pending] && options[:pending] != true
38
+ full_message << " (PENDING: #{options[:pending]})"
39
+ else
40
+ full_message << " (PENDING)"
41
+ end
42
+
43
+ output.puts yellow(full_message)
44
+ end
45
+
46
+ def example_step_failed(example_group, type, message, options)
47
+ full_message = "#{current_indentation} #{type.to_s.capitalize} #{message} (FAILED)"
48
+ output.puts red(full_message)
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ RSpec::Core::Formatters::DocumentationFormatter.send :include, ManiokBdd::RSpec::DocumentationFormatter
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ module ManiokBdd
3
+ module RSpec
4
+ module ExampleGroup
5
+ def include_steps(*args)
6
+ name = args.shift
7
+ shared_block = RSpec.world.shared_example_steps[name]
8
+ shared_block or raise ArgumentError, "Could not find shared steps #{name.inspect}"
9
+ instance_eval_with_args(*args, &shared_block)
10
+ end
11
+
12
+ def Given(message, options = {}, &block)
13
+ Step :given, message, options, &block
14
+ end
15
+
16
+ def When(message, options = {}, &block)
17
+ Step :when, message, options, &block
18
+ end
19
+
20
+ def Then(message, options = {}, &block)
21
+ Step :then, message, options, &block
22
+ end
23
+
24
+ def And(message, options = {}, &block)
25
+ Step :and, message, options, &block
26
+ end
27
+
28
+ def But(message, options = {}, &block)
29
+ Step :but, message, options, &block
30
+ end
31
+
32
+ private
33
+
34
+ def Step(type, message, options = {}, &block)
35
+ ::RSpec.world.reporter.example_step_started(self, type, message, options)
36
+ if block_given? && !options[:pending]
37
+ begin
38
+ yield block
39
+ rescue Exception => e
40
+ ::RSpec.world.reporter.example_step_failed(self, type, message, options)
41
+ raise e
42
+ end
43
+ ::RSpec.world.reporter.example_step_passed(self, type, message, options)
44
+ else
45
+ ::RSpec.world.reporter.example_step_pending(self, type, message, options)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ RSpec::Core::ExampleGroup.send :include, ManiokBdd::RSpec::ExampleGroup
54
+ RSpec::Core::ExampleGroup.singleton_class.define_example_method :Scenario, :with_steps => true
@@ -0,0 +1,15 @@
1
+ module ManiokBdd
2
+ module Features
3
+ def self.included(base)
4
+ base.instance_eval do
5
+ alias :Background :before
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ def self.Feature(*args, &block)
12
+ describe(*args, &block)
13
+ end
14
+
15
+ RSpec.configuration.include ManiokBdd::Features
@@ -0,0 +1,23 @@
1
+ module ManiokBdd
2
+ module RSpec
3
+ module Reporter
4
+ def example_step_started(example, type, message, options)
5
+ notify :example_step_started, example, type, message, options
6
+ end
7
+
8
+ def example_step_passed(example, type, message, options)
9
+ notify :example_step_passed, example, type, message, options
10
+ end
11
+
12
+ def example_step_pending(example, type, message, options)
13
+ notify :example_step_pending, example, type, message, options
14
+ end
15
+
16
+ def example_step_failed(example, type, message, options)
17
+ notify :example_step_failed, example, type, message, options
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ RSpec::Core::Reporter.send :include, ManiokBdd::RSpec::Reporter
@@ -0,0 +1,22 @@
1
+ module ManiokBdd
2
+ module RSpec
3
+ module SharedSteps
4
+
5
+ def shared_steps(name, &block)
6
+ ensure_shared_example_steps_name_not_taken(name)
7
+ RSpec.world.shared_example_steps[name] = block
8
+ end
9
+
10
+ private
11
+
12
+ def ensure_shared_example_steps_name_not_taken(name)
13
+ if RSpec.world.shared_example_steps.has_key?(name)
14
+ raise ArgumentError.new("Shared example steps '#{name}' already exists")
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
22
+ include ManiokBdd::RSpec::SharedSteps
@@ -0,0 +1,11 @@
1
+ module ManiokBdd
2
+ module RSpec
3
+ module World
4
+ def shared_example_steps
5
+ @shared_example_steps ||= {}
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ RSpec::Core::World.send :include, ManiokBdd::RSpec::World
@@ -1,3 +1,3 @@
1
1
  module ManiokBdd
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/maniok_bdd.rb CHANGED
@@ -1,4 +1,18 @@
1
- require "maniok_bdd/version"
1
+ require 'maniok_bdd/version'
2
2
 
3
3
  module ManiokBdd
4
4
  end
5
+
6
+ require 'rspec/core/formatters/base_formatter'
7
+ require 'rspec/core/formatters/documentation_formatter'
8
+ require "rspec/core/example_group"
9
+ require 'rspec/core/reporter'
10
+ require 'rspec/core/world'
11
+
12
+ require 'maniok_bdd/rspec/features'
13
+ require 'maniok_bdd/rspec/base_formatter'
14
+ require 'maniok_bdd/rspec/documentation_formatter'
15
+ require 'maniok_bdd/rspec/example_group'
16
+ require 'maniok_bdd/rspec/reporter'
17
+ require 'maniok_bdd/rspec/world'
18
+ require 'maniok_bdd/rspec/shared_steps'
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: maniok_bdd
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jean-Michel Garnier
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: jean-michel@21croissants.com
@@ -18,6 +18,15 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
+ - lib/maniok_bdd/cli.rb
22
+ - lib/maniok_bdd/gherkin_formatter.rb
23
+ - lib/maniok_bdd/rspec/base_formatter.rb
24
+ - lib/maniok_bdd/rspec/documentation_formatter.rb
25
+ - lib/maniok_bdd/rspec/example_group.rb
26
+ - lib/maniok_bdd/rspec/features.rb
27
+ - lib/maniok_bdd/rspec/reporter.rb
28
+ - lib/maniok_bdd/rspec/shared_steps.rb
29
+ - lib/maniok_bdd/rspec/world.rb
21
30
  - lib/maniok_bdd/version.rb
22
31
  - lib/maniok_bdd.rb
23
32
  homepage: http://github.com/21croissants/maniok_bdd
@@ -34,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
34
43
  version: '0'
35
44
  segments:
36
45
  - 0
37
- hash: 3479588527671171048
46
+ hash: -2301873164338472506
38
47
  none: false
39
48
  required_rubygems_version: !ruby/object:Gem::Requirement
40
49
  requirements:
@@ -43,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
52
  version: '0'
44
53
  segments:
45
54
  - 0
46
- hash: 3479588527671171048
55
+ hash: -2301873164338472506
47
56
  none: false
48
57
  requirements: []
49
58
  rubyforge_project: