Class: Chibineko::RSpec::ExampleGroupExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/chibineko/rspec/example_group_exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exgroup, testcase) ⇒ ExampleGroupExporter

Returns a new instance of ExampleGroupExporter.



6
7
8
9
# File 'lib/chibineko/rspec/example_group_exporter.rb', line 6

def initialize(exgroup, testcase)
  self.root = exgroup
  self.testcase = testcase
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



5
6
7
# File 'lib/chibineko/rspec/example_group_exporter.rb', line 5

def root
  @root
end

#testcaseObject

Returns the value of attribute testcase.



5
6
7
# File 'lib/chibineko/rspec/example_group_exporter.rb', line 5

def testcase
  @testcase
end

Instance Method Details

#create_example(parent, item) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chibineko/rspec/example_group_exporter.rb', line 27

def create_example(parent, item)
  
  if item.pending?
    parent.it "#{item.item}" do
      pending(item.memo)
    end
  elsif item.skip?
    parent.xit "#{item.item}" do
      expect(item).to be_ok            
    end
  else
    parent.it "#{item.item}" do |ex|
      # TODO 専用のMatcherつくろう
      expect(item).to be_ok
    end
  end
end

#export(parent = root, items = testcase.items, depth = 0) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/chibineko/rspec/example_group_exporter.rb', line 11

def export(parent=root,items=testcase.items,depth=0)
  exporter = self
  items.group_by {|item|
    item.groups[depth]
  }.each {|group,items|
    if group
      parent.describe "#{group}" do
        exporter.export(self, items, depth + 1)
      end
    else
      items.each do |item|
        create_example(parent,item)
      end
    end
  }
end