Tom Hoen
2009-Oct-21 13:08 UTC
[rspec-users] How can I test the values of css style attributes assigned to a div
My site allows users to change the backround color (among other things) for their page. These values are stored in database. Their choices (or the default) are placed on the page using a <style> block at the end of the <head> block in the layout. Here is what the style block looks like. <% if !!school %> <style> div#header { color: #<%= (!!school.school_name_color and !school.school_name_color.blank?) ? school.school_name_color : "ffffff" %>; background-color: #<%= (!!school.header_color and !school.header_color.blank?) ? school.header_color : "6FA9C7" %>; } div#header a { color: #<%= (!!school.school_name_color and !school.school_name_color.blank?) ? school.school_name_color : "ffffff" %>; } </style> <% end %> Can anyone suggest how to verify that the <div id=''header''> is assigned the css attribute color: #ffffff or color: #<% school.header_color%>. Best, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091021/7ed0f17d/attachment-0001.html>
David Chelimsky
2009-Oct-21 15:32 UTC
[rspec-users] How can I test the values of css style attributes assigned to a div
On Oct 21, 2009, at 8:08 AM, Tom Hoen wrote:> My site allows users to change the backround color (among other > things) for their page. These values are stored in database. > > Their choices (or the default) are placed on the page using a > <style> block at the end of the <head> block in the layout. Here is > what the style block looks like. > > <% if !!school %> > <style> > div#header { > color: #<%= (!!school.school_name_color and ! > school.school_name_color.blank?) ? school.school_name_color : > "ffffff" %>; > background-color: #<%= (!!school.header_color and ! > school.header_color.blank?) ? school.header_color : "6FA9C7" %>; > } > div#header a { > color: #<%= (!!school.school_name_color and ! > school.school_name_color.blank?) ? school.school_name_color : > "ffffff" %>; > } > </style> > <% end %> > > Can anyone suggest how to verify that the <div id=?header?> is > assigned the css attribute color: #ffffff or color: #<% > school.header_color%>.I''d move all of this logic to a helper, where it is way easier to spec: describe WhateverHelper do context "with a school" do it "renders the color for that school" do school = ... # whatever a school is helper.color_for(school).should == ... end end context "without a school" do ... end end Now you can do this in the view: <% if !!school %> <style> div#header { color: #<%= color_for(school) %>; background-color: #<%= header_color_for(school) %>; } div#header a { color: #<%= color_for(school) %>; } </style> <% end %> HTH, David> > Best, > Tom > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersCheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091021/b1264492/attachment-0001.html>