Skip to content

Commit

Permalink
Added some specs for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Apr 17, 2011
1 parent 8117a82 commit 94ddba2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
xpath (0.1.2)
xpath (0.1.3)
nokogiri (~> 1.3)

GEM
Expand Down
48 changes: 48 additions & 0 deletions spec/fixtures/form.html
Expand Up @@ -96,3 +96,51 @@ <h1>Form</h1>
</tr>
</table>
</p>

<p>
<h2>Fields</h2>

<h4>With id</h4>
<input id="input-with-id" value="correct-value" data="input-with-id-data"/>
<input type="text" id="input-text-with-id" data="input-text-with-id-data"/>
<input type="password" id="input-password-with-id" data="input-password-with-id-data"/>
<input type="custom" id="input-custom-with-id" data="input-custom-with-id-data"/>
<textarea id="textarea-with-id" data="textarea-with-id-data">Correct value</textarea>
<select id="select-with-id" data="select-with-id-data"></select>
<input type="submit" id="input-submit-with-id" data="input-submit-with-id-data"/>
<input type="image" id="input-image-with-id" data="input-image-with-id-data"/>
<input type="hidden" id="input-hidden-with-id" data="input-hidden-with-id-data"/>

<h4>With name</h4>
<input name="input-with-name" data="input-with-name-data"/>
<input type="text" name="input-text-with-name" data="input-text-with-name-data"/>
<input type="password" name="input-password-with-name" data="input-password-with-name-data"/>
<input type="custom" name="input-custom-with-name" data="input-custom-with-name-data"/>
<textarea name="textarea-with-name" data="textarea-with-name-data"></textarea>
<select name="select-with-name" data="select-with-name-data"></select>
<input type="submit" name="input-submit-with-name" data="input-submit-with-name-data"/>
<input type="image" name="input-image-with-name" data="input-image-with-name-data"/>
<input type="hidden" name="input-hidden-with-name" data="input-hidden-with-name-data"/>

<h4>With referenced label</h4>
<label for="input-with-label">Input with label</label><input id="input-with-label" data="input-with-label-data"/>
<label for="input-text-with-label">Input text with label</label><input type="text" id="input-text-with-label" data="input-text-with-label-data"/>
<label for="input-password-with-label">Input password with label</label><input type="password" id="input-password-with-label" data="input-password-with-label-data"/>
<label for="input-custom-with-label">Input custom with label</label><input type="custom" id="input-custom-with-label" data="input-custom-with-label-data"/>
<label for="textarea-with-label">Textarea with label</label><textarea id="textarea-with-label" data="textarea-with-label-data"></textarea>
<label for="select-with-label">Select with label</label><select id="select-with-label" data="select-with-label-data"></select>
<label for="input-submit-with-label">Input submit with label</label><input type="submit" id="input-submit-with-label" data="input-submit-with-label-data"/>
<label for="input-image-with-label">Input image with label</label><input type="image" id="input-image-with-label" data="input-image-with-label-data"/>
<label for="input-hidden-with-label">Input hidden with label</label><input type="hidden" id="input-hidden-with-label" data="input-hidden-with-label-data"/>

<h4>With parent label</h4>
<label>Input with parent label<input data="input-with-parent-label-data"/></label>
<label>Input text with parent label<input type="text" data="input-text-with-parent-label-data"/></label>
<label>Input password with parent label<input type="password" data="input-password-with-parent-label-data"/></label>
<label>Input custom with parent label<input type="custom" data="input-custom-with-parent-label-data"/></label>
<label>Textarea with parent label<textarea data="textarea-with-parent-label-data"></textarea></label>
<label>Select with parent label<select data="select-with-parent-label-data"></select></label>
<label>Input submit with parent label<input type="submit" data="input-submit-with-parent-label-data"/></label>
<label>Input image with parent label<input type="image" data="input-image-with-parent-label-data"/></label>
<label>Input hidden with parent label<input type="hidden" data="input-hidden-with-parent-label-data"/></label>
</p>
97 changes: 60 additions & 37 deletions spec/html_spec.rb
Expand Up @@ -106,55 +106,58 @@ def all(*args)
subject { :field }

context "by id" do
it("finds inputs with text type") {}
it("finds inputs with password type") {}
it("finds inputs with custom type") {}
it("finds textareas") {}
it("finds select boxes") {}
it("does not find submit buttons") {}
it("does not find image buttons") {}
it("does not find hidden fields") {}
it("finds inputs with no type") { get('input-with-id').should == 'input-with-id-data' }
it("finds inputs with text type") { get('input-text-with-id').should == 'input-text-with-id-data' }
it("finds inputs with password type") { get('input-password-with-id').should == 'input-password-with-id-data' }
it("finds inputs with custom type") { get('input-custom-with-id').should == 'input-custom-with-id-data' }
it("finds textareas") { get('textarea-with-id').should == 'textarea-with-id-data' }
it("finds select boxes") { get('select-with-id').should == 'select-with-id-data' }
it("does not find submit buttons") { get('input-submit-with-id').should be_nil }
it("does not find image buttons") { get('input-image-with-id').should be_nil }
it("does not find hidden fields") { get('input-hidden-with-id').should be_nil }
end

context "by name" do
it("finds inputs with text type") {}
it("finds inputs with password type") {}
it("finds inputs with custom type") {}
it("finds textareas") {}
it("finds select boxes") {}
it("does not find submit buttons") {}
it("does not find image buttons") {}
it("does not find hidden fields") {}
it("finds inputs with no type") { get('input-with-name').should == 'input-with-name-data' }
it("finds inputs with text type") { get('input-text-with-name').should == 'input-text-with-name-data' }
it("finds inputs with password type") { get('input-password-with-name').should == 'input-password-with-name-data' }
it("finds inputs with custom type") { get('input-custom-with-name').should == 'input-custom-with-name-data' }
it("finds textareas") { get('textarea-with-name').should == 'textarea-with-name-data' }
it("finds select boxes") { get('select-with-name').should == 'select-with-name-data' }
it("does not find submit buttons") { get('input-submit-with-name').should be_nil }
it("does not find image buttons") { get('input-image-with-name').should be_nil }
it("does not find hidden fields") { get('input-hidden-with-name').should be_nil }
end

context "by referenced label" do
it("finds inputs with text type") {}
it("finds inputs with password type") {}
it("finds inputs with custom type") {}
it("finds textareas") {}
it("finds select boxes") {}
it("does not find submit buttons") {}
it("does not find image buttons") {}
it("does not find hidden fields") {}
it("finds inputs with no type") { get('Input with label').should == 'input-with-label-data' }
it("finds inputs with text type") { get('Input text with label').should == 'input-text-with-label-data' }
it("finds inputs with password type") { get('Input password with label').should == 'input-password-with-label-data' }
it("finds inputs with custom type") { get('Input custom with label').should == 'input-custom-with-label-data' }
it("finds textareas") { get('Textarea with label').should == 'textarea-with-label-data' }
it("finds select boxes") { get('Select with label').should == 'select-with-label-data' }
it("does not find submit buttons") { get('Input submit with label').should be_nil }
it("does not find image buttons") { get('Input image with label').should be_nil }
it("does not find hidden fields") { get('Input hidden with label').should be_nil }
end

context "by parent label" do
it("finds inputs with text type") { get('Label text').should == 'id-text' }
it("finds inputs where label has problem chars") { get("Label text's got an apostrophe").should == 'id-problem-text' }
it("finds inputs with password type") {}
it("finds inputs with custom type") {}
it("finds textareas") {}
it("finds select boxes") {}
it("does not find submit buttons") {}
it("does not find image buttons") {}
it("does not find hidden fields") {}
it("finds inputs with no type") { get('Input with parent label').should == 'input-with-parent-label-data' }
it("finds inputs with text type") { get('Input text with parent label').should == 'input-text-with-parent-label-data' }
it("finds inputs with password type") { get('Input password with parent label').should == 'input-password-with-parent-label-data' }
it("finds inputs with custom type") { get('Input custom with parent label').should == 'input-custom-with-parent-label-data' }
it("finds textareas") { get('Textarea with parent label').should == 'textarea-with-parent-label-data' }
it("finds select boxes") { get('Select with parent label').should == 'select-with-parent-label-data' }
it("does not find submit buttons") { get('Input submit with parent label').should be_nil }
it("does not find image buttons") { get('Input image with parent label').should be_nil }
it("does not find hidden fields") { get('Input hidden with parent label').should be_nil }
end

context "with :with option" do
it("finds inputs that match option") {}
it("omits inputs that don't match option") {}
it("finds textareas that match option") {}
it("omits textareas that don't match option") {}
it("finds inputs that match option") { get('input-with-id', :with => 'correct-value').should == 'input-with-id-data' }
it("omits inputs that don't match option") { get('input-with-id', :with => 'wrong-value').should be_nil }
it("finds textareas that match option") { get('textarea-with-id', :with => 'Correct value').should == 'textarea-with-id-data' }
it("omits textareas that don't match option") { get('textarea-with-id', :with => 'Wrong value').should be_nil }
end

context "with :checked option" do
Expand Down Expand Up @@ -182,6 +185,26 @@ def all(*args)

end

describe '#select' do

end

describe '#checkbox' do

end

describe '#radio_button' do

end

describe '#file_field' do

end

describe '#option' do

end

describe "#optgroup" do
subject { :optgroup }

Expand Down

0 comments on commit 94ddba2

Please sign in to comment.