Module: Integrity::Notifier::Test

Defined in:
lib/integrity/notifier/test.rb,
lib/integrity/notifier/test/hpricot_matcher.rb

Defined Under Namespace

Classes: HpricotMatcher

Instance Method Summary collapse

Instance Method Details

#assert_form_have_option(option, value = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/integrity/notifier/test.rb', line 30

def assert_form_have_option(option, value=nil)
  selector = "input##{notifier.downcase}_notifier_#{option}"
  selector << "[@name='notifiers[#{notifier}][#{option}]']"
  selector << "[@value='#{value}']" if value

  assert_form_have_tag(selector, option => value)
end

#assert_form_have_options(*options) ⇒ Object



38
39
40
# File 'lib/integrity/notifier/test.rb', line 38

def assert_form_have_options(*options)
  options.each { |option| assert_form_have_option(option) }
end

#assert_form_have_tag(selector, options = {}) ⇒ Object



42
43
44
45
# File 'lib/integrity/notifier/test.rb', line 42

def assert_form_have_tag(selector, options={})
  content = options.delete(:content)
  assert_have_tag(form(options), selector, content)
end

#assert_have_tag(html, selector, content = nil) ⇒ Object



47
48
49
50
51
# File 'lib/integrity/notifier/test.rb', line 47

def assert_have_tag(html, selector, content=nil)
  matcher = HpricotMatcher.new(html)
  assert_equal content, matcher.tag(selector) if content
  assert matcher.tag(selector)
end

#form(config = {}) ⇒ Object



53
54
55
56
# File 'lib/integrity/notifier/test.rb', line 53

def form(config={})
  Haml::Engine.new(notifier_class.to_haml).
    render(OpenStruct.new(:config => config))
end

#notification(commit) ⇒ Object



18
19
20
# File 'lib/integrity/notifier/test.rb', line 18

def notification(commit)
  notifier_class.new(commit).full_message
end

#notification_failedObject



26
27
28
# File 'lib/integrity/notifier/test.rb', line 26

def notification_failed
  notification(Integrity::Commit.gen(:failed))
end

#notification_successfulObject



22
23
24
# File 'lib/integrity/notifier/test.rb', line 22

def notification_successful
  notification(Integrity::Commit.gen(:successful))
end

#notifier_classObject



14
15
16
# File 'lib/integrity/notifier/test.rb', line 14

def notifier_class
  Integrity::Notifier.const_get(notifier)
end

#setup_databaseObject



9
10
11
12
# File 'lib/integrity/notifier/test.rb', line 9

def setup_database
  DataMapper.setup(:default, "sqlite3::memory:")
  DataMapper.auto_migrate!
end