This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9da3f7
commit 2d1cf72
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module RSpec::TagMatchers | ||
def have_checkbox | ||
HasCheckbox.new | ||
end | ||
|
||
class HasCheckbox < HasInput | ||
def initialize | ||
super | ||
with_attribute(:type => :checkbox) | ||
end | ||
|
||
def checked | ||
with_attribute(:checked => true) | ||
self | ||
end | ||
|
||
def not_checked | ||
with_attribute(:checked => false) | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
|
||
describe RSpec::TagMatchers::HasCheckbox do | ||
include RSpec::TagMatchers | ||
|
||
describe "matching checkbox tags" do | ||
context "have_checkbox" do | ||
subject { have_checkbox } | ||
it { should_not match("<input />") } | ||
it { should match("<input type='checkbox' />") } | ||
it { should match("<input TYPE='CHECKBOX' />") } | ||
it { should_not match("<input type='text' />") } | ||
it { should_not match("<input type='checkboxer' />") } | ||
it { should_not match("input checkbox") } | ||
end | ||
end | ||
|
||
describe "matching checkbox state" do | ||
context "have_checkbox.checked" do | ||
subject { have_checkbox.checked } | ||
it { should_not match("<input type='checkbox' />") } | ||
it { should match("<input type='checkbox' checked />") } | ||
it { should match("<input type='checkbox' checked='checked' />") } | ||
it { should match("<input type='checkbox' checked='1' />") } | ||
end | ||
|
||
context "have_checkbox.not_checked" do | ||
subject { have_checkbox.not_checked } | ||
it { should match("<input type='checkbox' />") } | ||
it { should_not match("<input type='checkbox' checked />") } | ||
it { should_not match("<input type='checkbox' checked='checked' />") } | ||
it { should_not match("<input type='checkbox' checked='1' />") } | ||
end | ||
end | ||
|
||
describe "matching input names" do | ||
context "have_checkbox.for(:user => :admin)" do | ||
subject { have_checkbox.for(:user => :admin) } | ||
it { should_not match("<input type='checkbox' />") } | ||
it { should_not match("<input type='checkbox' name='user' />") } | ||
it { should match("<input type='checkbox' name='user[admin]' />") } | ||
it { should_not match("<input type='checkbox' name='user[admin][root]' />") } | ||
end | ||
end | ||
end |