kelp 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +91 -0
  4. data/MIT-LICENSE +22 -0
  5. data/README.md +16 -0
  6. data/Rakefile +16 -0
  7. data/docs/Makefile +130 -0
  8. data/docs/_static/custom.css +9 -0
  9. data/docs/conf.py +217 -0
  10. data/docs/development.rst +27 -0
  11. data/docs/future.rst +9 -0
  12. data/docs/index.rst +33 -0
  13. data/docs/make.bat +155 -0
  14. data/docs/testing.rst +15 -0
  15. data/docs/usage.rst +85 -0
  16. data/kelp.gemspec +25 -0
  17. data/lib/kelp.rb +1 -0
  18. data/lib/kelp/capybara.rb +2 -0
  19. data/lib/kelp/capybara/capybara_steps.rb +225 -0
  20. data/lib/kelp/capybara/form_helper.rb +131 -0
  21. data/lib/kelp/capybara/web_helper.rb +148 -0
  22. data/spec/capybara/click_link_in_row_spec.rb +24 -0
  23. data/spec/capybara/dropdown_spec.rb +112 -0
  24. data/spec/capybara/field_should_be_empty_spec.rb +44 -0
  25. data/spec/capybara/field_should_contain_spec.rb +143 -0
  26. data/spec/capybara/fill_in_fields_spec.rb +67 -0
  27. data/spec/capybara/follow_spec.rb +35 -0
  28. data/spec/capybara/page_should_have_spec.rb +48 -0
  29. data/spec/capybara/page_should_not_have_spec.rb +53 -0
  30. data/spec/capybara/press_spec.rb +33 -0
  31. data/spec/capybara/should_be_disabled_spec.rb +28 -0
  32. data/spec/capybara/should_be_enabled_spec.rb +29 -0
  33. data/spec/capybara/should_not_see_spec.rb +97 -0
  34. data/spec/capybara/should_see_in_same_row_spec.rb +41 -0
  35. data/spec/capybara/should_see_spec.rb +80 -0
  36. data/spec/capybara/spec_helper.rb +22 -0
  37. data/spec/test_app/test_app.rb +18 -0
  38. data/spec/test_app/views/about.erb +9 -0
  39. data/spec/test_app/views/edit1.erb +9 -0
  40. data/spec/test_app/views/edit2.erb +9 -0
  41. data/spec/test_app/views/edit3.erb +9 -0
  42. data/spec/test_app/views/form.erb +38 -0
  43. data/spec/test_app/views/home.erb +46 -0
  44. data/spec/test_app/views/thanks.erb +10 -0
  45. metadata +183 -0
@@ -0,0 +1,143 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe FormHelper, "#field_should_contain" do
4
+ before(:each) do
5
+ visit('/form')
6
+ end
7
+
8
+ context "passes when" do
9
+ context "field with id" do
10
+ it "has the given value" do
11
+ fill_in "first_name", :with => "Brian"
12
+ field_should_contain "first_name", "Brian"
13
+ end
14
+ end
15
+
16
+ context "field with label" do
17
+ it "has the given value" do
18
+ fill_in "First name", :with => "Brian"
19
+ field_should_contain "First name", "Brian"
20
+ end
21
+ end
22
+ end
23
+
24
+ context "fails when" do
25
+ context "field with id" do
26
+ it "is empty" do
27
+ lambda do
28
+ field_should_contain "first_name", "Brian"
29
+ end.should raise_error
30
+ end
31
+
32
+ it "has a different value" do
33
+ fill_in "first_name", :with => "Judith"
34
+ lambda do
35
+ field_should_contain "first_name", "Brian"
36
+ end.should raise_error
37
+ end
38
+ end
39
+
40
+ context "field with label" do
41
+ it "is empty" do
42
+ lambda do
43
+ field_should_contain "First name", "Brian"
44
+ end.should raise_error
45
+ end
46
+
47
+ it "has a different value" do
48
+ fill_in "First name", :with => "Judith"
49
+ lambda do
50
+ field_should_contain "First name", "Brian"
51
+ end.should raise_error
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+
60
+ describe FormHelper, "#fields_should_contain" do
61
+ before(:each) do
62
+ visit('/form')
63
+ end
64
+
65
+ context "passes when" do
66
+ context "fields with ids" do
67
+ it "all match" do
68
+ fill_in "first_name", :with => "Terry"
69
+ fill_in "last_name", :with => "Jones"
70
+ fields_should_contain "first_name" => "Terry", "last_name" => "Jones"
71
+ end
72
+
73
+ it "all match with some empty" do
74
+ fill_in "first_name", :with => "Terry"
75
+ fields_should_contain "first_name" => "Terry", "last_name" => ""
76
+ end
77
+
78
+ it "all match with some dropdowns" do
79
+ fill_in "first_name", :with => "Terry"
80
+ fill_in "last_name", :with => "Jones"
81
+ select "Average", :from => "height"
82
+ fields_should_contain "first_name" => "Terry", "last_name" => "Jones", "height" => "Average"
83
+ end
84
+ end
85
+
86
+ context "fields with labels" do
87
+ it "all match" do
88
+ fill_in "First name", :with => "Terry"
89
+ fill_in "Last name", :with => "Jones"
90
+ fields_should_contain "First name" => "Terry", "Last name" => "Jones"
91
+ end
92
+
93
+ it "all match with some empty" do
94
+ fill_in "First name", :with => "Terry"
95
+ fields_should_contain "First name" => "Terry", "Last name" => ""
96
+ end
97
+
98
+ it "all match with some dropdowns" do
99
+ fill_in "First name", :with => "Terry"
100
+ fill_in "Last name", :with => "Jones"
101
+ select "Average", :from => "Height"
102
+ fields_should_contain "First name" => "Terry", "Last name" => "Jones", "Height" => "Average"
103
+ end
104
+ end
105
+ end
106
+
107
+ context "fails when" do
108
+ context "fields with ids" do
109
+ it "are empty" do
110
+ lambda do
111
+ fields_should_contain "first_name" => "Terry", "last_name" => "Jones"
112
+ end.should raise_error
113
+ end
114
+
115
+ it "do not all match" do
116
+ fill_in "first_name", :with => "Terry"
117
+ fill_in "last_name", :with => "Gilliam"
118
+ lambda do
119
+ fields_should_contain "first_name" => "Terry", "last_name" => "Jones"
120
+ end.should raise_error
121
+ end
122
+ end
123
+
124
+ context "fields with labels" do
125
+ it "are empty" do
126
+ lambda do
127
+ fields_should_contain "First name" => "Terry", "Last name" => "Jones"
128
+ end.should raise_error
129
+ end
130
+
131
+ it "do not all match" do
132
+ fill_in "First name", :with => "Terry"
133
+ fill_in "Last name", :with => "Gilliam"
134
+ lambda do
135
+ fields_should_contain "First name" => "Terry", "Last name" => "Jones"
136
+ end.should raise_error
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
@@ -0,0 +1,67 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe FormHelper, "#fill_in_fields" do
4
+ before(:each) do
5
+ visit('/form')
6
+ end
7
+
8
+ context "passes when" do
9
+ it "filling a single field by id" do
10
+ fill_in_fields "first_name" => "Mel"
11
+ field_should_contain "first_name", "Mel"
12
+ end
13
+
14
+ it "filling a single field by label" do
15
+ fill_in_fields "First name" => "Mel"
16
+ field_should_contain "First name", "Mel"
17
+ end
18
+
19
+ it "filling multiple fields by id" do
20
+ fill_in_fields \
21
+ "first_name" => "Mel",
22
+ "last_name" => "Brooks"
23
+ field_should_contain "first_name", "Mel"
24
+ field_should_contain "last_name", "Brooks"
25
+ end
26
+
27
+ it "filling multiple fields by label" do
28
+ fill_in_fields \
29
+ "First name" => "Mel",
30
+ "Last name" => "Brooks"
31
+ field_should_contain "First name", "Mel"
32
+ field_should_contain "Last name", "Brooks"
33
+ end
34
+
35
+ it "filling a single field by id within a scope" do
36
+ fill_in_fields_within "#person_form", "first_name" => "Mel"
37
+ field_should_contain "first_name", "Mel"
38
+ end
39
+
40
+ it "filling multiple fields by id within a scope" do
41
+ fill_in_fields_within "#person_form",
42
+ "first_name" => "Mel",
43
+ "last_name" => "Brooks"
44
+ fields_should_contain_within "#person_form",
45
+ "first_name" => "Mel",
46
+ "last_name" => "Brooks"
47
+ end
48
+ end
49
+
50
+ context "fails when" do
51
+ it "filling a nonexistent field" do
52
+ lambda do
53
+ fill_in_fields "Middle name" => "Kaminsky"
54
+ end.should raise_error
55
+ end
56
+
57
+ it "filling a field in the wrong scope" do
58
+ lambda do
59
+ fill_in_fields_within "#other_form",
60
+ "First name" => "Mel"
61
+ end.should raise_error
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebHelper, "#follow" do
4
+ before(:each) do
5
+ visit('/home')
6
+ end
7
+
8
+ context "passes when" do
9
+ it "link exists" do
10
+ follow "About Us"
11
+ should_see "We're a small company with an even smaller webpage"
12
+ end
13
+
14
+ it "link is within the scope" do
15
+ follow "About Us", :within => "#links"
16
+ should_see "We're a small company with an even smaller webpage"
17
+ end
18
+ end
19
+
20
+ context "fails when" do
21
+ it "link does not exist" do
22
+ lambda do
23
+ follow "About Them"
24
+ end.should raise_error
25
+ end
26
+
27
+ it "link is not within the scope" do
28
+ lambda do
29
+ follow "About Us", :within => "#invalid_scope"
30
+ end.should raise_error
31
+ end
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebHelper, "#page_should_have" do
4
+ before(:each) do
5
+ visit('/home')
6
+ end
7
+
8
+ context "passes when" do
9
+ context "String" do
10
+ it "exists" do
11
+ page_should_have "Hello world"
12
+ page_should_have "Goodbye world"
13
+ end
14
+ end
15
+ context "Regexp" do
16
+ it "matches" do
17
+ page_should_have /(Hello|Goodbye) world/
18
+ page_should_have /\d\d\d-\d\d\d\d/
19
+ end
20
+ end
21
+ end
22
+
23
+ context "fails when" do
24
+ context "String" do
25
+ it "does not exist" do
26
+ lambda do
27
+ page_should_have "Wazzup world"
28
+ end.should raise_error
29
+ end
30
+ end
31
+
32
+ context "Regexp" do
33
+ it "does not match" do
34
+ lambda do
35
+ page_should_have /(Foo|Bar|Baz) world/
36
+ end.should raise_error
37
+ end
38
+ end
39
+
40
+ it "not a String or Regexp" do
41
+ lambda do
42
+ page_should_have 123
43
+ end.should raise_error
44
+ end
45
+ end
46
+
47
+ end
48
+
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebHelper, "#page_should_not_have" do
4
+ before(:each) do
5
+ visit('/home')
6
+ end
7
+
8
+ context "passes when" do
9
+ context "String" do
10
+ it "does not exist" do
11
+ page_should_not_have "Wazzup world"
12
+ end
13
+ end
14
+
15
+ context "Regexp" do
16
+ it "does not match" do
17
+ page_should_not_have /(Foo|Bar|Baz) world/
18
+ end
19
+ end
20
+ end
21
+
22
+ context "fails when" do
23
+ context "String" do
24
+ it "exists" do
25
+ lambda do
26
+ page_should_not_have "Hello world"
27
+ end.should raise_error
28
+ lambda do
29
+ page_should_not_have "Goodbye world"
30
+ end.should raise_error
31
+ end
32
+ end
33
+ context "Regexp" do
34
+ it "matches" do
35
+ lambda do
36
+ page_should_not_have /(Hello|Goodbye) world/
37
+ end.should raise_error
38
+ lambda do
39
+ page_should_not_have /\d\d\d-\d\d\d\d/
40
+ end.should raise_error
41
+ end
42
+ end
43
+
44
+ it "not a String or Regexp" do
45
+ lambda do
46
+ page_should_not_have 123
47
+ end.should raise_error
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebHelper, "#press" do
4
+ before(:each) do
5
+ visit('/home')
6
+ end
7
+
8
+ context "passes when" do
9
+ it "button exists" do
10
+ press "Submit"
11
+ end
12
+
13
+ it "button exists within the scope" do
14
+ press "Submit", :within => "#fields"
15
+ end
16
+ end
17
+
18
+ context "fails when" do
19
+ it "button does not exist" do
20
+ lambda do
21
+ press "Poke"
22
+ end.should raise_error
23
+ end
24
+
25
+ it "button exists but is not within the scope" do
26
+ lambda do
27
+ press "Submit", :within => "#greeting"
28
+ end.should raise_error
29
+ end
30
+ end
31
+ end
32
+
33
+
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebHelper, "#should_be_disabled" do
4
+ before(:each) do
5
+ visit('/form')
6
+ end
7
+
8
+ context "passes when" do
9
+ it "element has the disabled attribute" do
10
+ should_be_disabled "readonly"
11
+ end
12
+ end
13
+
14
+ context "fails when" do
15
+ it "element does not exist" do
16
+ lambda do
17
+ should_be_disabled "nonexistent"
18
+ end.should raise_error
19
+ end
20
+
21
+ it "element does not have the disabled attribute" do
22
+ lambda do
23
+ should_be_disabled "first_name"
24
+ end.should raise_error
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebHelper, "#should_be_enabled" do
4
+ before(:each) do
5
+ visit('/form')
6
+ end
7
+
8
+ context "passes when" do
9
+ it "element does not have the disabled attribute" do
10
+ should_be_enabled "first_name"
11
+ end
12
+ end
13
+
14
+ context "fails when" do
15
+ it "element does not exist" do
16
+ lambda do
17
+ should_be_enabled "nonexistent"
18
+ end.should raise_error
19
+ end
20
+
21
+ it "element has the disabled attribute" do
22
+ lambda do
23
+ should_be_enabled "readonly"
24
+ end.should raise_error
25
+ end
26
+ end
27
+ end
28
+
29
+