Module: Daddy::Cucumber::Assert

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

Instance Method Summary collapse

Instance Method Details

#assert_check(field_name) ⇒ Object



42
43
44
45
# File 'lib/daddy/cucumber/assert.rb', line 42

def assert_check(field_name)
  check field_name
  capture
end

#assert_choose(field_name) ⇒ Object



52
53
54
55
# File 'lib/daddy/cucumber/assert.rb', line 52

def assert_choose(field_name)
  choose field_name
  capture
end

#assert_content_type(content_type) ⇒ Object



80
81
82
# File 'lib/daddy/cucumber/assert.rb', line 80

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

#assert_fill_in(field_name, value) ⇒ Object



37
38
39
40
# File 'lib/daddy/cucumber/assert.rb', line 37

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

#assert_iterate(array) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/daddy/cucumber/assert.rb', line 84

def assert_iterate(array)
  iterated = false
  
  array.each do |x|
    iterated ||= yield x
  end
  
  fail 'テスト対象のデータがありません。' unless iterated
end

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



67
68
69
70
# File 'lib/daddy/cucumber/assert.rb', line 67

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



76
77
78
# File 'lib/daddy/cucumber/assert.rb', line 76

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

#assert_present(value, message = nil) ⇒ Object



72
73
74
# File 'lib/daddy/cucumber/assert.rb', line 72

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

#assert_select(name, value) ⇒ Object



57
58
59
60
# File 'lib/daddy/cucumber/assert.rb', line 57

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

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



62
63
64
65
# File 'lib/daddy/cucumber/assert.rb', line 62

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

#assert_uncheck(field_name) ⇒ Object



47
48
49
50
# File 'lib/daddy/cucumber/assert.rb', line 47

def assert_uncheck(field_name)
  uncheck field_name
  capture
end

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



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

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

  # パスのチェック
  re = path.gsub(/\//, '\/')
  assert /#{re}/ =~ current_path, "想定しているパスではありません。想定 #{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



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

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



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

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