bdd 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ # ruby abc_spec.rb
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
4
+
5
+ require 'bdd/minitest'
6
+ require 'minitest/autorun'
7
+
8
+ Minitest::Reporters.use!(Bdd::Minitest::Reporter.new)
9
+
10
+ describe 'BDD' do
11
+ describe "abc" do
12
+ before(:each) do
13
+ Given 'it works with explicit filters' do
14
+ assert true
15
+ end
16
+ end
17
+
18
+ Given 'it works with implicit filters' do
19
+ assert true
20
+ end
21
+
22
+ it "has love" do
23
+ Given "it has some love" do
24
+ assert true
25
+ end
26
+ When "it needs love" do
27
+ assert true
28
+ end
29
+ Then "it has love" do
30
+ assert true
31
+ end
32
+ end
33
+
34
+ it "doesn't has love" do
35
+ Given "it does not have love" do
36
+ assert true
37
+ end
38
+ When "it needs love" do
39
+ assert true
40
+ end
41
+ Then "it has no love (this is failing on purpose for demo)" do
42
+ assert false
43
+ end
44
+ end
45
+
46
+ it "will love" do
47
+ Given "it does not have love" do
48
+ assert true
49
+ end
50
+ When "it needs love" do
51
+ assert true
52
+ end
53
+ Then "it will love later (this is failing on purpose for demo)" do
54
+ skip "wip"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ # rspec abc_spec.rb
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
4
+
5
+ require 'bdd/rspec'
6
+
7
+ RSpec.configure do |config|
8
+ config.color = true
9
+ config.default_formatter = Bdd::RSpec::Formatter
10
+ end
11
+
12
+ describe 'BDD' do
13
+ describe "abc" do
14
+ before(:each) do
15
+ Given 'it works with explicit filters' do
16
+ expect(true).to eq true
17
+ end
18
+ end
19
+
20
+ Given 'it works with implicit filters' do
21
+ expect(true).to eq true
22
+ end
23
+
24
+ it "has love" do
25
+ Given "it has some love" do
26
+ expect(true).to eq true
27
+ end
28
+ When "it needs love" do
29
+ expect(true).to eq true
30
+ end
31
+ Then "it has love" do
32
+ expect(true).to eq true
33
+ end
34
+ end
35
+
36
+ it "doesn't has love" do
37
+ Given "it does not have love" do
38
+ expect(true).to eq true
39
+ end
40
+ When "it needs love" do
41
+ expect(true).to eq true
42
+ end
43
+ Then "it has no love (this is failing on purpose for demo)" do
44
+ expect(true).to eq false
45
+ end
46
+ end
47
+
48
+ it "will love" do
49
+ Given "it does not have love" do
50
+ expect(true).to eq true
51
+ end
52
+ When "it needs love" do
53
+ expect(true).to eq true
54
+ end
55
+ Then "it will love later (this is failing on purpose for demo)"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1 @@
1
+ all spec files in this folder will produce exactly the same outcome
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Zombie' do
4
+
5
+ it 'is alive' do
6
+ Given 'pre-condition A' do
7
+ expect(1).to eq(1)
8
+ end
9
+
10
+ When 'it performs action B' do
11
+ expect(1).to eq(1)
12
+ end
13
+
14
+ Then 'post-condition AB is expected' do
15
+ expect(1).to eq(1)
16
+ end
17
+
18
+ Then 'and it is stil a zombie' do
19
+ expect(1).to eq(1)
20
+ end
21
+ end
22
+
23
+ it 'is dead' do
24
+ Given 'pre-condition A' do
25
+ expect(1).to eq(1)
26
+ end
27
+
28
+ When 'it performs action C' do
29
+ expect(1).to eq(1)
30
+ end
31
+
32
+ Then 'post-condition AC is expected' do
33
+ expect(1).to eq(1)
34
+ end
35
+
36
+ Then 'and it is stil a zombie' do
37
+ expect(1).to eq(1)
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Zombie' do
4
+
5
+ before(:each) do
6
+ Given 'pre-condition A' do
7
+ expect(1).to eq(1)
8
+ end
9
+ end
10
+
11
+ after(:each) do
12
+ Then 'and it is stil a zombie' do
13
+ expect(1).to eq(1)
14
+ end
15
+ end
16
+
17
+ it 'is alive' do
18
+ When 'it performs action B' do
19
+ expect(1).to eq(1)
20
+ end
21
+
22
+ Then 'post-condition AB is expected' do
23
+ expect(1).to eq(1)
24
+ end
25
+ end
26
+
27
+ it 'is dead' do
28
+ When 'it performs action C' do
29
+ expect(1).to eq(1)
30
+ end
31
+
32
+ Then 'post-condition AC is expected' do
33
+ expect(1).to eq(1)
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+
40
+
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Zombie' do
4
+
5
+ Given 'pre-condition A' do
6
+ expect(1).to eq(1)
7
+ end
8
+
9
+ Then 'and it is stil a zombie' do
10
+ expect(1).to eq(1)
11
+ end
12
+
13
+ it 'is alive' do
14
+ When 'it performs action B' do
15
+ expect(1).to eq(1)
16
+ end
17
+
18
+ Then 'post-condition AB is expected' do
19
+ expect(1).to eq(1)
20
+ end
21
+ end
22
+
23
+ it 'is dead' do
24
+ When 'it performs action C' do
25
+ expect(1).to eq(1)
26
+ end
27
+
28
+ Then 'post-condition AC is expected' do
29
+ expect(1).to eq(1)
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+
36
+
37
+
38
+
39
+
40
+
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ class Zombie
4
+ def initialize
5
+ @brains = 0
6
+ end
7
+ def eat(brains)
8
+ @brains += brains
9
+ end
10
+ def hungry?
11
+ @brains < 3
12
+ end
13
+ end
14
+
15
+ describe Zombie do
16
+
17
+ let (:zombie) { Zombie.new }
18
+
19
+ it "Is naturally hungry" do
20
+ Given "zombie is instantiated" do
21
+ zombie
22
+ end
23
+ Then "zombie should be hungry" do
24
+ expect(zombie.hungry?).to eq(true)
25
+ end
26
+
27
+ end
28
+
29
+ it "Does not satisfy with 1 brain" do
30
+ # this comment
31
+ When "zombie eats 1 brain" do
32
+ zombie.eat(1)
33
+ end
34
+ # does not show in your test output
35
+ Then "zombie should still be hungry" do
36
+ expect(zombie.hungry?).to eq(true)
37
+ end
38
+ end
39
+
40
+ it "Does not satisfy with 2 brains" do
41
+ # so start using bdd gem today
42
+ When "zombie eats 2 brains" do
43
+ zombie.eat(2)
44
+ end
45
+ # and make your tests STAND OUT
46
+ Then "zombie should no longer hungry" do
47
+ expect(zombie.hungry?).to eq(false)
48
+ end
49
+ end
50
+
51
+ it "Is not completely written yet" do
52
+ # so start using bdd gem today
53
+ When "zombie eats 2 brains" do
54
+ zombie.eat(2)
55
+ end
56
+ # and make your tests STAND OUT
57
+ Then "zombie should <write code here>"
58
+ end
59
+ end
data/lib/bdd.rb CHANGED
@@ -1,15 +1,12 @@
1
- require "bdd/version"
2
- require "rspec/core"
3
-
4
- require "colorize"
5
-
6
-
7
-
8
- require "bdd/rspec"
9
- # TODO: require "bdd/test_unit" # if
10
- # TODO: require "bdd/minitest" # if
11
-
12
-
13
1
  module Bdd
14
- # Your code goes here...
2
+ autoload :Adapters, 'bdd/adapters'
3
+ autoload :Colors, 'bdd/colors'
4
+ autoload :StringBuilder, 'bdd/string_builder'
5
+ autoload :Title, 'bdd/title'
6
+ autoload :Check, 'bdd/check'
15
7
  end
8
+
9
+ require "bdd/version"
10
+ require "bdd/class_methods"
11
+
12
+ Bdd::Check.new
@@ -0,0 +1,7 @@
1
+ module Bdd
2
+ module Adapters
3
+ autoload :Base, 'bdd/adapters/base'
4
+ autoload :RSpecAdapter, 'bdd/adapters/rspec_adapter'
5
+ autoload :MinitestAdapter, 'bdd/adapters/minitest_adapter'
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ module Bdd
2
+ module Adapters
3
+ class Base
4
+ def self.register
5
+ Bdd.adapters << adapter = new
6
+ adapter.register
7
+ Bdd.define(%w[Given], %w[When Then], %w[And But])
8
+ end
9
+
10
+ def register
11
+ # implementation must set these ivars
12
+ @example_module.const_set(:ClassMethods, Module.new)
13
+ @formatter_class.send :include, @formatter_module
14
+ @framework_example_class.send :include, @example_module
15
+ @framework_example_class.send :extend, @example_module::ClassMethods
16
+ end
17
+
18
+ def define(pre_conditions, post_conditions, conjunctions)
19
+ _define_conditions(:before, pre_conditions)
20
+ _define_conditions(:after, post_conditions)
21
+ _define_conjunctions(conjunctions)
22
+ end
23
+
24
+ private
25
+
26
+ def _define_conditions(placement, titles)
27
+ titles.each do |title|
28
+ @example_module::ClassMethods.send :define_method, title do |string, &block|
29
+ send(placement, :each) do
30
+ send(title, string) do
31
+ instance_eval(&block)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def _define_conjunctions(titles)
39
+ titles.each do |title|
40
+ @example_module.send :define_method, title do |string, &block|
41
+ bdd_step(title, string, &block)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,56 @@
1
+ module Bdd
2
+ module Adapters
3
+ class MinitestAdapter < Base
4
+
5
+ def initialize
6
+ @example_module = Test
7
+ @formatter_module = Reporter
8
+ @formatter_class = Bdd::Minitest::Reporter
9
+ @framework_example_class = ::Minitest::Test
10
+ end
11
+
12
+ module Reporter
13
+ def record_print_status(test)
14
+ super
15
+ if test.bdd_container.any?
16
+ puts test.bdd_container
17
+ puts
18
+ end
19
+ test.bdd_container.clear
20
+ end
21
+ end
22
+
23
+ module Test
24
+ def bdd_step(title, string, &block)
25
+ @bdd_nesting ||= 0
26
+ @bdd_nesting += 1
27
+ sb = StringBuilder.new(title)
28
+
29
+ if block_given?
30
+ yield
31
+ sb.append_success(string)
32
+ else
33
+ skip
34
+ end
35
+
36
+ rescue ::Minitest::Skip
37
+ sb.append_pending(string)
38
+ raise
39
+ rescue ::Minitest::Assertion
40
+ sb.append_failure(string)
41
+ raise
42
+ ensure
43
+ @bdd_nesting -= 1
44
+ if @bdd_nesting.zero?
45
+ bdd_container << sb.string
46
+ end
47
+ end
48
+
49
+ def bdd_container
50
+ @bdd_container ||= Bdd.get_container(object_id)
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end