technicalpickles-nice_assert_select 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +39 -0
- data/VERSION.yml +4 -0
- data/lib/nice_assert_select.rb +36 -0
- data/test/test_helper.rb +14 -0
- data/test/test_nice_assert_select.rb +69 -0
- metadata +58 -0
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= nice_assert_select
|
2
|
+
|
3
|
+
Tired of ugly assert_select calls?
|
4
|
+
|
5
|
+
assert_select "form[action=?][method=post]", sources_path do
|
6
|
+
assert_select "input[type=text][name=?]", 'source[name]'
|
7
|
+
assert_select "input[type=hidden][name=_method][value=put]"
|
8
|
+
assert_select "input[type=submit]"
|
9
|
+
end
|
10
|
+
|
11
|
+
How about some nice assert_selects?
|
12
|
+
|
13
|
+
assert_select form(:action => :post, :action => sources_path) do
|
14
|
+
assert_select text_field(:name => 'source[name]')
|
15
|
+
assert_select form_method_field(:put)
|
16
|
+
assert_select submit_button
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
nice_assert_select provides helpers for making the calls more rubyish and more readable. Currently, they are mostly limited to form related selectors that do attribute matching.
|
21
|
+
|
22
|
+
form
|
23
|
+
text_field
|
24
|
+
hidden_field
|
25
|
+
password_field
|
26
|
+
form_method_field (this is the hidden field Rails uses for determing what HTTP method to use, since browsers are generally limited to GET and POST)
|
27
|
+
submit_button
|
28
|
+
|
29
|
+
It is by no means comprehensive, as it was extracted from a project which only needed this selectors.
|
30
|
+
|
31
|
+
== Installing
|
32
|
+
|
33
|
+
For Rails 2.1 and on, add this to your +config/environment.rb+:
|
34
|
+
|
35
|
+
config.gem 'technicalpickles-nice_assert_select', :lib => 'nice_assert_select', :source => 'http://gems.github.com'
|
36
|
+
|
37
|
+
== COPYRIGHT
|
38
|
+
|
39
|
+
Copyright (c) 2009 Josh Nichols. See LICENSE for details.
|
data/VERSION.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module NiceAssertSelect
|
2
|
+
def build_html_selector(prefix, attributes = {})
|
3
|
+
attribute_selector = attributes.keys.map {|key| "[#{key}=?]"}.join('')
|
4
|
+
HTML.selector("#{prefix}#{attribute_selector}", *attributes.values)
|
5
|
+
end
|
6
|
+
|
7
|
+
def form(attributes)
|
8
|
+
build_html_selector('form', attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def text_field(attributes)
|
12
|
+
build_html_selector('input', attributes.merge(:type => 'text'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def hidden_field(attributes)
|
16
|
+
build_html_selector('input', attributes.merge(:type => 'hidden'))
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def password_field(attributes)
|
21
|
+
build_html_selector('input', attributes.merge(:type => 'password'))
|
22
|
+
end
|
23
|
+
|
24
|
+
def submit_button
|
25
|
+
build_html_selector('input', :type => 'submit')
|
26
|
+
end
|
27
|
+
|
28
|
+
def form_method_field(method)
|
29
|
+
hidden_field(:name => '_method', :value => method)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ActionController::TestCase.class_eval do
|
34
|
+
include NiceAssertSelect
|
35
|
+
end
|
36
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
require 'action_controller'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
+
require 'nice_assert_select'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
include NiceAssertSelect
|
14
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestNiceAssertSelect < Test::Unit::TestCase
|
4
|
+
|
5
|
+
|
6
|
+
context "build_html_selector for form without attributes" do
|
7
|
+
should 'use HTML.selector("form")' do
|
8
|
+
HTML.expects(:selector).with('form')
|
9
|
+
|
10
|
+
build_html_selector('form')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "build_html selector for form with attributes" do
|
15
|
+
should "use HTML.selector('form[action=/foo]')" do
|
16
|
+
HTML.expects(:selector).with('form[action=?]', '/foo')
|
17
|
+
|
18
|
+
build_html_selector('form', :action => '/foo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "form with action => /foo" do
|
23
|
+
should "use build_html_selector('form', :action => '/foo')" do
|
24
|
+
expects(:build_html_selector).with('form', :action => '/foo')
|
25
|
+
|
26
|
+
form(:action => '/foo')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "text_field with name 'foo' and value 'bar'" do
|
31
|
+
should "use build_html_selector('input', :type => 'text', :name => 'foo', :value => 'bar')" do
|
32
|
+
expects(:build_html_selector).with('input', :type => 'text', :name => 'foo', :value => 'bar')
|
33
|
+
|
34
|
+
text_field(:name => 'foo', :value => 'bar')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "hidden_field with name 'foo'" do
|
39
|
+
should "use build_html_selector('input', :type => 'hidden', :name => 'foo')" do
|
40
|
+
expects(:build_html_selector).with('input', :type => 'hidden', :name => 'foo')
|
41
|
+
|
42
|
+
hidden_field(:name => 'foo')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "password_field with name 'foo'" do
|
47
|
+
should "use build_html_selector('input', :type => 'password', :name => 'foo'" do
|
48
|
+
expects(:build_html_selector).with('input', :type => 'password', :name => 'foo')
|
49
|
+
|
50
|
+
password_field(:name => 'foo')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "submit_button" do
|
55
|
+
should "use build_html_selector('input', :type => 'submit')" do
|
56
|
+
expects(:build_html_selector).with('input', :type => 'submit')
|
57
|
+
|
58
|
+
submit_button
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "form_method_field for :put" do
|
63
|
+
should "use hidden_field(:name => '_method', :value => :put)" do
|
64
|
+
expects(:hidden_field).with(:name => '_method', :value => :put)
|
65
|
+
|
66
|
+
form_method_field(:put)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: technicalpickles-nice_assert_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Nichols
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-18 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: make assert_select nicer
|
17
|
+
email: josh@technicalpickles.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- VERSION.yml
|
27
|
+
- lib/nice_assert_select.rb
|
28
|
+
- test/test_helper.rb
|
29
|
+
- test/test_nice_assert_select.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/technicalpickles/nice_assert_select
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --inline-source
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: make assert_select nicer
|
57
|
+
test_files: []
|
58
|
+
|