Class: Buildr::Groovy::EasyB

Inherits:
TestFramework::JavaBDD
  • Object
show all
Defined in:
lib/buildr/groovy/bdd.rb

Overview

EasyB is a Groovy based BDD framework. To use in your project:

test.using :easyb

This framework will search in your project for:

src/spec/groovy/**/*Story.groovy
src/spec/groovy/**/*Specification.groovy

Support the following options:

  • :format – Report format :txt or :xml, default is :txt

  • :properties – Hash of properties passed to the test suite.

  • :java_args – Arguments passed to the JVM.

Constant Summary collapse

VERSION =
"0.9"
TESTS_PATTERN =
[ /(Story|Specification).groovy$/ ]
OPTIONS =
[:format, :properties, :java_args]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applies_to?(project) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/buildr/groovy/bdd.rb', line 51

def applies_to?(project) #:nodoc:
  %w{
    **/*Specification.groovy **/*Story.groovy
  }.any? { |glob| !Dir[project.path_to(:source, bdd_dir, lang, glob)].empty? }
end

.dependenciesObject



45
46
47
48
49
# File 'lib/buildr/groovy/bdd.rb', line 45

def dependencies
  @dependencies ||= ["org.easyb:easyb:jar:#{version}",
    'org.codehaus.groovy:groovy:jar:1.5.3','asm:asm:jar:2.2.3',
    'commons-cli:commons-cli:jar:1.0','antlr:antlr:jar:2.7.7']
end

.versionObject



41
42
43
# File 'lib/buildr/groovy/bdd.rb', line 41

def version
  Buildr.settings.build['jbehave'] || VERSION
end

Instance Method Details

#run(tests, dependencies) ⇒ Object

:nodoc:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/buildr/groovy/bdd.rb', line 70

def run(tests, dependencies) #:nodoc:
  options = { :format => :txt }.merge(self.options).only(*OPTIONS)

  if :txt == options[:format]
    easyb_format, ext = 'txtstory', '.txt'
  elsif :xml == options[:format]
    easyb_format, ext = 'xmlbehavior', '.xml'
  else
    raise "Invalid format #{options[:format]} expected one of :txt :xml"
  end

  cmd_args = [ 'org.disco.easyb.BehaviorRunner' ]
  cmd_options = { :properties => options[:properties],
                  :java_args => options[:java_args],
                  :classpath => dependencies }

  tests.inject([]) do |passed, test|
    name = test.sub(/.*?groovy[\/\\]/, '').pathmap('%X')
    report = File.join(task.report_to.to_s, name + ext)
    mkpath report.pathmap('%d')
    begin
      Java::Commands.java cmd_args,
         "-#{easyb_format}", report,
         test, cmd_options.merge(:name => name)
    rescue => e
      passed
    else
      passed << test
    end
  end
end

#tests(dependencies) ⇒ Object

:nodoc:



65
66
67
68
# File 'lib/buildr/groovy/bdd.rb', line 65

def tests(dependencies) #:nodoc:
  Dir[task.project.path_to(:source, bdd_dir, lang, "**/*.groovy")].
    select { |name| TESTS_PATTERN.any? { |pat| pat === name } }
end