Class: Lucid::InterfaceRb::RbLanguage

Inherits:
Object
  • Object
show all
Includes:
Lucid::Interface::InterfaceMethods
Defined in:
lib/lucid/interface_rb/rb_language.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Lucid::Interface::InterfaceMethods

#add_hook, #add_transform, #after, #after_configuration, #around, #available_step_definition, #before, #clear_hooks, #execute_after_step, #execute_transforms, #hooks_for, #invoked_step_definition, #unmatched_step_definitions

Constructor Details

#initialize(runtime) ⇒ RbLanguage

Returns a new instance of RbLanguage.



42
43
44
45
46
47
48
# File 'lib/lucid/interface_rb/rb_language.rb', line 42

def initialize(runtime)
  @runtime = runtime
  @step_definitions = []
  RbLucid.rb_language = self
  @domain_proc = @domain_modules = nil
  @assertions_module = find_best_assertions_module
end

Instance Attribute Details

#current_domainObject (readonly)

Returns the value of attribute current_domain.



36
37
38
# File 'lib/lucid/interface_rb/rb_language.rb', line 36

def current_domain
  @current_domain
end

#step_definitionsObject (readonly)

Returns the value of attribute step_definitions.



36
37
38
# File 'lib/lucid/interface_rb/rb_language.rb', line 36

def step_definitions
  @step_definitions
end

Instance Method Details

#begin_rb_scenario(scenario) ⇒ Object



73
74
75
76
77
# File 'lib/lucid/interface_rb/rb_language.rb', line 73

def begin_rb_scenario(scenario)
  create_domain
  extend_domain
  connect_domain(scenario)
end

#build_rb_world_factory(domain_modules, proc) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/lucid/interface_rb/rb_language.rb', line 93

def build_rb_world_factory(domain_modules, proc)
  if(proc)
    raise MultipleDomain.new(@domain_proc, proc) if @domain_proc
    @domain_proc = proc
  end
  @domain_modules ||= []
  @domain_modules += domain_modules
end

#find_best_assertions_moduleObject



50
51
52
53
54
55
56
# File 'lib/lucid/interface_rb/rb_language.rb', line 50

def find_best_assertions_module
  begin
    ::RSpec::Matchers
  rescue NameError
    ::Test::Unit::Assertions
  end
end

#load_code_file(code_file) ⇒ Object



102
103
104
105
106
# File 'lib/lucid/interface_rb/rb_language.rb', line 102

def load_code_file(code_file)
  # This is what will allow self.add_step_definition, self.add_hook,
  # and self.add_transform to be called from RbLucid.
  load File.expand_path(code_file)
end

#matcher_text(code_keyword, step_name, multiline_arg_class, matcher_type = :regexp) ⇒ Object



68
69
70
71
# File 'lib/lucid/interface_rb/rb_language.rb', line 68

def matcher_text(code_keyword, step_name, multiline_arg_class, matcher_type = :regexp)
  matcher_class = typed_matcher_class(matcher_type)
  matcher_class.new(code_keyword, step_name, multiline_arg_class).to_s
end

#register_rb_hook(phase, tag_expressions, proc) ⇒ Object



79
80
81
# File 'lib/lucid/interface_rb/rb_language.rb', line 79

def register_rb_hook(phase, tag_expressions, proc)
  add_hook(phase, RbHook.new(self, tag_expressions, proc))
end

#register_rb_step_definition(regexp, proc_or_sym, options) ⇒ Object



87
88
89
90
91
# File 'lib/lucid/interface_rb/rb_language.rb', line 87

def register_rb_step_definition(regexp, proc_or_sym, options)
  step_definition = RbStepDefinition.new(self, regexp, proc_or_sym, options)
  @step_definitions << step_definition
  step_definition
end

#register_rb_transform(regexp, proc) ⇒ Object



83
84
85
# File 'lib/lucid/interface_rb/rb_language.rb', line 83

def register_rb_transform(regexp, proc)
  add_transform(RbTransform.new(self, regexp, proc))
end

#step_matches(name_to_match, name_to_format) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/lucid/interface_rb/rb_language.rb', line 58

def step_matches(name_to_match, name_to_format)
  @step_definitions.map do |step_definition|
    if(arguments = step_definition.arguments_from(name_to_match))
      StepMatch.new(step_definition, name_to_match, name_to_format, arguments)
    else
      nil
    end
  end.compact
end