Module: Daddy::Cucumber::Assert
- Defined in:
- lib/daddy/cucumber/assert.rb
Instance Method Summary collapse
- #assert_check(field_name) ⇒ Object
- #assert_choose(field_name) ⇒ Object
- #assert_content_type(content_type) ⇒ Object
- #assert_fill_in(field_name, value) ⇒ Object
- #assert_fill_in_rich(field_name, value) ⇒ Object
- #assert_iterate(array) ⇒ Object
- #assert_no_selector(selector, options = {}) ⇒ Object
- #assert_not_present(value, message = nil) ⇒ Object
- #assert_present(value, message = nil) ⇒ Object
- #assert_select(name, value) ⇒ Object
- #assert_selector(selector, options = {}) ⇒ Object
- #assert_uncheck(field_name) ⇒ Object
- #assert_url(path, params = {}) ⇒ Object
- #assert_visit(path, params = {}) ⇒ Object
- #get_current_params ⇒ Object
- #remove_domain(url) ⇒ Object
Instance Method Details
#assert_check(field_name) ⇒ Object
53 54 55 56 |
# File 'lib/daddy/cucumber/assert.rb', line 53 def assert_check(field_name) check field_name capture end |
#assert_choose(field_name) ⇒ Object
63 64 65 66 |
# File 'lib/daddy/cucumber/assert.rb', line 63 def assert_choose(field_name) choose field_name capture end |
#assert_content_type(content_type) ⇒ Object
91 92 93 |
# File 'lib/daddy/cucumber/assert.rb', line 91 def assert_content_type(content_type) assert_equal page.response_headers['Content-Type'], content_type end |
#assert_fill_in(field_name, value) ⇒ Object
43 44 45 46 |
# File 'lib/daddy/cucumber/assert.rb', line 43 def assert_fill_in(field_name, value) fill_in field_name, :with => value capture end |
#assert_fill_in_rich(field_name, value) ⇒ Object
48 49 50 51 |
# File 'lib/daddy/cucumber/assert.rb', line 48 def assert_fill_in_rich(field_name, value) fill_in_rich field_name, value capture end |
#assert_iterate(array) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/daddy/cucumber/assert.rb', line 95 def assert_iterate(array) iterated = false array.each do |x| iterated ||= yield x end fail 'テスト対象のデータがありません。' unless iterated end |
#assert_no_selector(selector, options = {}) ⇒ Object
78 79 80 81 |
# File 'lib/daddy/cucumber/assert.rb', line 78 def assert_no_selector(selector, = {}) assert page.has_no_selector?(selector), [:message] capture if [:capture] end |
#assert_not_present(value, message = nil) ⇒ Object
87 88 89 |
# File 'lib/daddy/cucumber/assert.rb', line 87 def assert_not_present(value, = nil) assert ! value.present?, end |
#assert_present(value, message = nil) ⇒ Object
83 84 85 |
# File 'lib/daddy/cucumber/assert.rb', line 83 def assert_present(value, = nil) assert value.present?, end |
#assert_select(name, value) ⇒ Object
68 69 70 71 |
# File 'lib/daddy/cucumber/assert.rb', line 68 def assert_select(name, value) select value, :from => name capture end |
#assert_selector(selector, options = {}) ⇒ Object
73 74 75 76 |
# File 'lib/daddy/cucumber/assert.rb', line 73 def assert_selector(selector, = {}) assert page.has_selector?(selector), [:message] capture if [:capture] end |
#assert_uncheck(field_name) ⇒ Object
58 59 60 61 |
# File 'lib/daddy/cucumber/assert.rb', line 58 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 21 22 23 24 25 26 |
# File 'lib/daddy/cucumber/assert.rb', line 6 def assert_url(path, params = {}) # スクリーンショットの保存 url_without_domain = remove_domain(current_url) begin capture url_without_domain rescue puts "URL: #{url_without_domain}" end # パスのチェック 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/daddy/cucumber/assert.rb', line 28 def assert_visit(path, params = {}) query_string = '' params.each do |key, value| if query_string.blank? 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_params ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/daddy/cucumber/assert.rb', line 105 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 |
#remove_domain(url) ⇒ Object
116 117 118 |
# File 'lib/daddy/cucumber/assert.rb', line 116 def remove_domain(url) url.sub(/http:\/\/([^\/:]+)(:[0-9]+)?\/(.+)/) { "/#{$3}" } end |