Rspec view test #385

Closed
wants to merge 14 commits into
from

Conversation

Projects
None yet
5 participants
Contributor

cesy commented Nov 27, 2011

Adding an rspec view test for the home page

If this is okay, it should serve as a model for coders to add view tests for other pages that need them.

Contributor

rbreu commented Nov 28, 2011

I very wary about just using 'contains' when testing the content of a whole page. E.g. the string 'fandoms' both appears in the navigation bar and the footer--which are you testing for? It's better to go via css selectors here (and maybe the existence of a css selector is enough already?)

Also your test is called "should display the welcome box" but you're testinig for more than that (news, fandoms) which should go in their own tests.

And as a note, view tests get interesting when there are views that display lots of different stuff in different situations (depending on who's logged in etc). E.g. https://github.com/rbreu/otwtranslation/blob/master/spec/views/languages/_selector.html.erb_spec.rb or https://github.com/rbreu/otwtranslation/blob/master/spec/views/translations/_translation.html.erb_spec.rb We don't have to replicate view spec tests when the views don't change much and are covered by Cucumber tests anyway. On the front page, one might check for the displaying of the News stuff depending on @admin_post for example.

Contributor

cesy commented Dec 13, 2011

I've made a few updates as per your suggestions - thank you. It's not currently passing on my webdev, though, so needs careful checking before merging - it seems to be failing on the part that passed before :s

Contributor

rbreu commented Dec 14, 2011

I've made it work on my branch, see the commit here: rbreu/otwarchive@f12fe34

You need the webrat gem (in the test environment) to get 'contain'. The admin_post factory you were trying to use was missing, you need a few additions to spec_helper.rb to get authlogic working, and the tests need a few more method stubs.

Contributor

cesy commented Dec 14, 2011

Thanks for the tips - I'd got the admin_post factory figured out, but was puzzled about the authlogic stuff. Do you know why it worked before and then stopped working?

Contributor

rbreu commented Dec 14, 2011

Your first tests were very simple, so the error might have started when you were beginning to stub out some of those logged_in/current_user helpers? Or emulating logged in views?

Contributor

cesy commented Dec 16, 2011

Currently results in the following failures, so not ready to be merged yet - I'm investigating.

  1. UsersController create with valid parameters should be successful
    Failure/Error: Unable to find matching line from backtrace
    NoMethodError:
    undefined method `request=' for nil:NilClass

    /home/cesy/.bundler/ruby/1.9.1/authlogic-a087ad0cba3c/lib/authlogic/controller_adapters/abstract_adapter.rb:63:in`method_missing'

  2. User save should prevent duplicate logins even when Rails validation misses it
    Failure/Error: lambda do
    expected ActiveRecord::RecordNotUnique but nothing was raised

    ./spec/models/user_spec.rb:66:in `block (3 levels) in <top (required)>'

Contributor

cesy commented Jan 20, 2012

Tests now all pass. Last pseud spec test can be uncommented after firewolf's changes are merged - I'll do a separate pull req for that when we're ready.

Owner

elzj commented Jan 21, 2012

Would it be better to use "have_content" instead of "contains" and stick with capybara so that we're not using both of them?

Contributor

cesy commented Jan 26, 2012

From what I can see (mainly on http://stackoverflow.com/questions/4706370/rspec-view-testing-with-capybara-and-rails3/4773050#4773050#), capybara doesn't support this properly in view specs, at least in the version we're using. Several people are recommending just using both systems at once. It might be possible once we've upgraded to a newer version of Rails and also update Capybara - I can look into it more then if you like?

Owner

shalott commented Feb 3, 2012

closing, see comment on pullreq #408 #408

@shalott shalott closed this Feb 3, 2012

@cesy cesy reopened this Feb 17, 2012

Contributor

cesy commented Feb 17, 2012

This should now be totally independent and working. For some reason github is showing things that are already in master, though - any ideas why?

@CristinaRO CristinaRO closed this Mar 1, 2013

@cesy cesy deleted the cesy:rspec branch Jan 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment