spec/ruhl_spec.rb in ruhl-1.2.0 vs spec/ruhl_spec.rb in ruhl-1.3.0
- old
+ new
@@ -1,5 +1,6 @@
+# encoding: UTF-8
require File.join(File.dirname(__FILE__), 'spec_helper')
describe Ruhl do
before do
@co = ContextObject.new
@@ -32,29 +33,63 @@
doc.xpath('//meta[@name="description"]').first['content'].
should == @co.generate_description
end
end
- describe "medium.html" do
+ describe "combination.html" do
before do
- @html = File.read html(:medium)
- @doc = create_doc
+ @html = File.read html(:combination)
end
- it "first data row should equal first user " do
- table = @doc.xpath('/html/body/table/tr//td')
+ it 'first data row should equal first user' do
+ doc = create_doc
+ table = doc.xpath('/html/body/table/tbody/tr//td')
table.children[0].to_s.should == "Jane"
table.children[1].to_s.should == "Doe"
table.children[2].to_s.should == "jane@stonean.com"
end
- it "last data row should equal last user " do
- table = @doc.xpath('/html/body/table/tr//td')
+ it 'last data row should equal last user' do
+ doc = create_doc
+ table = doc.xpath('/html/body/table/tbody/tr//td')
table.children[9].to_s.should == "Paul"
table.children[10].to_s.should == "Tin"
table.children[11].to_s.should == "paul@stonean.com"
end
+
+ it 'should append user_id to class' do
+ doc = create_doc
+ rows = doc.xpath('/html/body/table/tbody//tr')
+ rows.each do |row|
+ row['class'].should =~ /^user_data user_\d+$/
+ end
+ end
+
+ it 'should set href from hash' do
+ doc = create_doc
+ rows = doc.xpath("/html/body/ul[@id='ruby_urls']/li//a")
+ rows[0].inner_html.should == 'Ruby Lang'
+ rows[0]['href'].should == 'http://ruby-lang.org'
+ rows[1].inner_html.should == 'RubyonRails'
+ rows[1]['href'].should == 'http://rubyonrails.com'
+ rows[2].inner_html.should == 'RubyFlow'
+ rows[2]['href'].should == 'http://rubyflow.com'
+ rows[3].inner_html.should == 'RubyTrends'
+ rows[3]['href'].should == 'http://rubytrends.com'
+ end
+
+ it 'should use instance variable' do
+ doc = create_doc
+ p = doc.xpath("/html/body/p[@id='time']")
+ p.inner_html.should == 'It is now Peanut Butter Jelly time'
+ end
+
+ it 'should not use instance variable' do
+ Ruhl.use_instance_variables = false
+ lambda{ create_doc }.should raise_error(NoMethodError)
+ Ruhl.use_instance_variables = true
+ end
end
describe "fragment.html" do
before do
@html = File.read html(:fragment)
@@ -359,9 +394,14 @@
it "should have option for each state" do
options = @doc.xpath('/html/body/select//option')
options.children.length.should == @co.state_options.length
+ end
+
+ it "should have selected Georgia" do
+ state = @doc.xpath('/html/body/select//option[@selected]')
+ state[0]['value'].should == "GA"
end
end
end
describe "special.html" do