Module: Daddy::Cucumber::Assert

Defined in:
lib/daddy/cucumber/helpers/assert.rb

Instance Method Summary collapse

Instance Method Details

#assert_check(field_name) ⇒ Object



40
41
42
43
# File 'lib/daddy/cucumber/helpers/assert.rb', line 40

def assert_check(field_name)
  check field_name
  capture
end

#assert_choose(field_name) ⇒ Object



50
51
52
53
# File 'lib/daddy/cucumber/helpers/assert.rb', line 50

def assert_choose(field_name)
  choose field_name
  capture
end

#assert_content_type(content_type) ⇒ Object



78
79
80
# File 'lib/daddy/cucumber/helpers/assert.rb', line 78

def assert_content_type(content_type)
  assert_equal content_type, page.response_headers['Content-Type']
end

#assert_fill_in(field_name, value) ⇒ Object



35
36
37
38
# File 'lib/daddy/cucumber/helpers/assert.rb', line 35

def assert_fill_in(field_name, value)
  fill_in field_name, :with => value
  capture
end

#assert_iterate(array) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/daddy/cucumber/helpers/assert.rb', line 82

def assert_iterate(array)
  iterated = false

  array.each do |x|
    iterated ||= yield x
  end

  fail 'テスト対象のデータがありません。' unless iterated
end

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



65
66
67
68
# File 'lib/daddy/cucumber/helpers/assert.rb', line 65

def assert_no_selector(selector, options = {})
  assert page.has_no_selector?(selector), options[:message]
  capture if options[:capture]
end

#assert_not_present(value, message = nil) ⇒ Object



74
75
76
# File 'lib/daddy/cucumber/helpers/assert.rb', line 74

def assert_not_present(value, message = nil)
  assert ! value.present?, message
end

#assert_present(value, message = nil) ⇒ Object



70
71
72
# File 'lib/daddy/cucumber/helpers/assert.rb', line 70

def assert_present(value, message = nil)
  assert value.present?, message
end

#assert_select(name, value) ⇒ Object



55
56
57
58
# File 'lib/daddy/cucumber/helpers/assert.rb', line 55

def assert_select(name, value)
  select value, :from => name
  capture
end

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



60
61
62
63
# File 'lib/daddy/cucumber/helpers/assert.rb', line 60

def assert_selector(selector, options = {})
  assert page.has_selector?(selector), options[:message]
  capture if options[:capture]
end

#assert_uncheck(field_name) ⇒ Object



45
46
47
48
# File 'lib/daddy/cucumber/helpers/assert.rb', line 45

def assert_uncheck(field_name)
  uncheck field_name
  capture
end

#assert_url(path, params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/daddy/cucumber/helpers/assert.rb', line 4

def assert_url(path, params = {})
  # スクリーンショットの保存
  capture

  # パスのチェック
  re = path.gsub(/\//, '\/')
  assert has_current_path?(/#{re}/), "想定しているパスではありません。想定 #{path} : 実際 #{current_path}"

  # パラメータのチェック
  current_params = get_current_params()
  params.each do |key, value|
    re = value
    assert /#{re}/ =~ current_params[key], "#{key}が想定している値ではありません。想定 #{value} : 実際 #{current_params[key]}"
  end
end

#assert_visit(path, params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/daddy/cucumber/helpers/assert.rb', line 20

def assert_visit(path, params = {})
  query_string = ''
  params.each do |key, value|
    if query_string.empty?
      query_string += '?'
    else
      query_string += '&'
    end
    query_string += (key.to_s + '=' + value.to_s)
  end

  visit path + query_string
  assert_url path, params
end

#get_current_paramsObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/daddy/cucumber/helpers/assert.rb', line 92

def get_current_params
  ret = {}
  if current_url.include?('?')
    current_url.split('?')[1].split('&').each do |query_string|
      key, value = query_string.split('=')
      ret.store key.to_sym, value
    end
  end
  ret
end