Forum: RSpec spec'ing theme views

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
jared (Guest)
on 2009-04-07 08:01
(Received via mailing list)
I'm using the theme support plugin on one of my apps, and I would like
to spec the views for each of my themes, but having a little trouble
and hoping someone can point me in the right direction.

Themed views are located at /themes/my_theme/views that override the
views in app/views when that theme is active. I created a themes/
my_theme/spec directory, and to spec the file at /themes/my_theme/
views/default/index.html.erb I created the following file at themes/
my_theme/spec/default/index.html.erb_spec.rb

require File.expand_path(File.dirname(__FILE__) + '/../../../../spec/
spec_helper')

describe "/default/index.html.erb" do
  include DefaultHelper

  it "should render" do
    render
  end

end

Two major questions here:

1) I'm not sure what to put for the describe parameter since I'm
assuming "/default/index.html.erb" is referencing the app/views
directory

2) Running this spec gives:

NameError in '/default/index.html.erb should render'
undefined local variable or method `render' for
#<ActiveSupport::TestCase::Subclass_1:0x351dc24>
themes/my_theme/spec/default/index.html.erb_spec.rb:11:

any suggestions on how to approach this?

Thanks!
David C. (Guest)
on 2009-04-07 08:29
(Received via mailing list)
On Mon, Apr 6, 2009 at 7:06 PM, jared <removed_email_address@domain.invalid> 
wrote:
> require File.expand_path(File.dirname(__FILE__) + '/../../../../spec/
>
> Two major questions here:
>
> 1) I'm not sure what to put for the describe parameter since I'm
> assuming "/default/index.html.erb" is referencing the app/views
> directory

Try this:

describe "/default/index.html.erb", :type => :view do
 include DefaultHelper

 it "should render" do
   template.view_paths=(File.join(File.dirname(__FILE__),
"/../../../themes/my_theme/"))
   render
 end

end

Cheers,
David
Zach D. (Guest)
on 2009-04-07 08:59
(Received via mailing list)
On Mon, Apr 6, 2009 at 8:06 PM, jared <removed_email_address@domain.invalid> 
wrote:
> require File.expand_path(File.dirname(__FILE__) + '/../../../../spec/
>
> Two major questions here:
>
> 1) I'm not sure what to put for the describe parameter since I'm
> assuming "/default/index.html.erb" is referencing the app/views
> directory

This is a textual description used to help you. It doesn't actually
mean anything to rspec at this time AFAIK. RSpec is able to to treat
specs found in "spec/views/" as ViewExampleGroups based on the "view"
directory naming convention, IIRC.

>
> 2) Running this spec gives:
>
> NameError in '/default/index.html.erb should render'
> undefined local variable or method `render' for
> #<ActiveSupport::TestCase::Subclass_1:0x351dc24>
> themes/my_theme/spec/default/index.html.erb_spec.rb:11:
>
> any suggestions on how to approach this?

Try passing in :type => "view" to your describe. e.g.:

describe "your/partial", :type => "view" do
  # ...
end

Where does that take you?


>
> Thanks!
> _______________________________________________
> rspec-users mailing list
> removed_email_address@domain.invalid
> http://rubyforge.org/mailman/listinfo/rspec-users
>



--
Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
Phlip (Guest)
on 2009-04-07 09:10
(Received via mailing list)
David C. wrote:

> Try this:
>
> describe "/default/index.html.erb", :type => :view do
>  include DefaultHelper
>
>  it "should render" do
>    template.view_paths=(File.join(File.dirname(__FILE__),
> "/../../../themes/my_theme/"))
>    render
>  end

And why isn't that DRY with the matching /../../../themes code on the
production
side?

BTW, as a meta-answer, I implemented this algorithm for a test once...

  for each theme in themes/*
    render the theme
    assert the theme passes Tidy validation
    assert all the a hrefs point somewhere
    assert every image appears in public/images

Hours of fun! If you have two many themes, you can pick a random
assortment for
each integration test run...
David C. (Guest)
on 2009-04-07 09:24
(Received via mailing list)
On Mon, Apr 6, 2009 at 11:59 PM, Phlip <removed_email_address@domain.invalid> 
wrote:
>>   render
>>  end
>
> And why isn't that DRY with the matching /../../../themes code on the
> production side?

Because nobody has asked for support for views outside the standard
directories, and *you* haven't submitted a patch!

http://rspec.lighthouseapp.com

Cheers,
David
Phlip (Guest)
on 2009-04-07 16:44
(Received via mailing list)
David C. wrote:

>>>  it "should render" do
>>>   template.view_paths=(File.join(File.dirname(__FILE__),
>>> "/../../../themes/my_theme/"))
>>>   render
>>>  end
>> And why isn't that DRY with the matching /../../../themes code on the
>> production side?
>
> Because nobody has asked for support for views outside the standard
> directories, and *you* haven't submitted a patch!

I'd probably (mumble) get the architecture wrong...

BTW "DRY" does not strictly apply across the test/code boundary,
otherwise all
the test and code in the world would disappear with a "thoomp" into a
singularity.
This topic is locked and can not be replied to.