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
block
at the end of the 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

is assigned
the
css attribute color: #ffffff or color: #<% school.header_color%>.

Best,

Tom

On Oct 21, 2009, at 8:08 AM, Tom H. wrote:

              color: #<%= (!!school.school_name_color and ! 
  </style>

<% end %>

Can anyone suggest how to verify that the

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 %>

div#header { color: #<%= color_for(school) %>; background-color: #<%= header_color_for(school) %>; } div#header a { color: #<%= color_for(school) %>; }

<% end %>

HTH,
David

Best,
Tom


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Cheers,
David