Class: Azebiki::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/azebiki/azebiki.rb

Defined Under Namespace

Classes: MatcherBuilder, MatcherProxy, MyHaveSelector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, parent_checker = nil, &block) ⇒ Checker

Returns a new instance of Checker.



227
228
229
230
231
232
233
234
235
236
237
# File 'lib/azebiki/azebiki.rb', line 227

def initialize(content, parent_checker=nil, &block)
  @content = content
  @errors = []
  @have_matchers = []
  @self_before_instance_eval = eval "self", block.binding
  @matcher_builder = MatcherBuilder.new(&block)
  @parent_checker = parent_checker
  build_contents
  build_matchers
  run_matchers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



274
275
276
# File 'lib/azebiki/azebiki.rb', line 274

def method_missing(method, *args, &block)
  @self_before_instance_eval.send method, *args, &block
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



225
226
227
# File 'lib/azebiki/azebiki.rb', line 225

def content
  @content
end

#errorsObject

Returns the value of attribute errors.



225
226
227
# File 'lib/azebiki/azebiki.rb', line 225

def errors
  @errors
end

#have_matchersObject

Returns the value of attribute have_matchers.



225
226
227
# File 'lib/azebiki/azebiki.rb', line 225

def have_matchers
  @have_matchers
end

#parent_checkerObject

Returns the value of attribute parent_checker.



225
226
227
# File 'lib/azebiki/azebiki.rb', line 225

def parent_checker
  @parent_checker
end

Instance Method Details

#contains(matching_text) ⇒ Object



239
240
241
242
243
# File 'lib/azebiki/azebiki.rb', line 239

def contains(matching_text)
  selector = MatcherProxy.new(Webrat::Matchers::HasContent.new(matching_text))
  @have_matchers << selector
  selector
end

#matches(name, attributes = {}, &block) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/azebiki/azebiki.rb', line 246

def matches(name, attributes = {}, &block)
  if block_given?
    parent_checker = @parent_checker || self
    have = MyHaveSelector.new(name, attributes) do |n|
      Azebiki::Checker.new(n, parent_checker, &block).success?
    end
    
    selector = MatcherProxy.new(have)
  else
    selector = MatcherProxy.new(MyHaveSelector.new(name, attributes))
  end
  
  @have_matchers << selector
  selector
end

#success?Boolean

Returns:

  • (Boolean)


262
263
264
# File 'lib/azebiki/azebiki.rb', line 262

def success?
  @success
end