public
Description: Culerity unobtrusive javascript example
Homepage:
Clone URL: git://github.com/drogus/culerity-javascript-example.git
drogus (author)
Mon Jul 20 05:16:09 -0700 2009
commit  85b4dfda5d76f1aee28d632eef1ff57047515ebd
tree    c638da5d4983d13fa6f4aa0320bbc45060378ae7
parent  ce020082c8dbde0774b736a5a407167f6f230ba7
100644 78 lines (63 sloc) 2.1 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
 
Given /^I am on (.+)$/ do |page_name|
  $browser.goto(@host + path_to(page_name))
  assert_successful_response
end
 
When /I press "(.*)"/ do |button|
  $browser.button(:text, button).click
  assert_successful_response
end
 
When /I follow "(.*)"/ do |link|
  $browser.link(:text, /#{link}/).click
  assert_successful_response
end
 
When /I fill in "(.*)" for "(.*)"/ do |value, field|
  $browser.text_field(:id, find_label(field).for).set(value)
end
 
When /I check "(.*)"/ do |field|
  $browser.check_box(:id, find_label(field).for).set(true)
end
 
When /^I uncheck "(.*)"$/ do |field|
  $browser.check_box(:id, find_label(field).for).set(false)
end
 
When /I select "(.*)" from "(.*)"/ do |value, field|
  $browser.select_list(:id, find_label(field).for).select value
end
 
When /I choose "(.*)"/ do |field|
  $browser.radio(:id, find_label(field).for).set(true)
end
 
When /I go to (.+)/ do |path|
  $browser.goto @host + path_to(path)
  assert_successful_response
end
 
When /I wait for the AJAX call to finish/ do
  $browser.wait
end
 
Then /I should see "(.*)"/ do |text|
  # if we simply check for the browser.html content we don't find content that has been added dynamically, e.g. after an ajax call
  unless $browser.document.asXml =~ /#{text}/
    raise("'#{text}' not found")
  end
end
 
Then /I should not see "(.*)"/ do |text|
  div = $browser.div(:text, /#{text}/).html rescue nil
  div.should be_nil
end
 
def find_label(text)
  $browser.label :text, text
end
 
def assert_successful_response
  status = $browser.page.web_response.status_code
  if(status == 302 || status == 301)
    location = $browser.page.web_response.get_response_header_value('Location')
    puts "Being redirected to #{location}"
    $browser.goto location
    assert_successful_response
  elsif status != 200
    tmp = Tempfile.new 'culerity_results'
    tmp << $browser.html
    tmp.close
    `open -a /Applications/Safari.app #{tmp.path}`
    raise "Brower returned Response Code #{$browser.page.web_response.status_code}"
  end
end