I have two situations where I am getting undefined method errors when the 
code works as expected.

Example 1:

Here is the rspec error

Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined method `*visible?*' for nil:NilClass
     # ./app/views/users/show.html.erb:3:in 
`_app_views_users_show_html_erb__3654591023925520049_70206011948440'
     # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top 
(required)>'

Here is a portion of the code in show.html.erb

<% when current_user?(@user) || (!current_user?(@user) && *
current_user.visible?* && @user.visible && @user.active_user == '3') || 
current_user.admin? %>
    <% provide(:title, @user.first_name+' '[email protected]_name) %>
    <aside class="span4">
      <section><br>
      <%= gravatar_for @user %> 
      <span style="font-weight: bold; padding-left: 5px; color: #f8ee5f; 
font-size: 136%;"><%= @user.first_name %> <%= @user.last_name %></span><br>
      <span style="padding-left: 5px;"><%= @user.city %>, <%= 
@user.state_province %>, <!-- <%= @state_name %> --> <%= @country_name 
%></span><br>
      <span style="font-weight: bold; padding-left: 5px; color: 
#f8ee5f;">Username: </span><span style="padding-left: 5px;"><%= 
@user.username %></span><br><br>
    <span style="word-wrap: break-word; text-align: justify; width: 
305px;"><%= @user.bio %></span>
        <% if current_user?(@user) %>
          <br><br><span style="font-weight: bold;"><%= link_to 'Click here 
to edit your profile!', edit_user_path(@user) %></span>
        <% end %>
      </section>  .......etc.

Here is the code in user_pages_spec.rb

    before { visit user_path(user) }

Example 2 - These tests were working then all of a sudden they quit working 
without any code changes.  The code works as expected.

Here is the rspec error

    Failure/Error: expect { click_button submit }.to change(User, 
:count).by(1)
     NoMethodError:
       undefined method `name' for nil:NilClass
     # ./app/mailers/user_mailer.rb:14:in `acctcre_email'
     # ./app/controllers/users_controller.rb:48:in `create'
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:215:in `block (5 levels) in <top 
(required)>'
     # ./spec/requests/user_pages_spec.rb:215:in `block (4 levels) in <top 
(required)>'


Here is the code in user_mailer

def acctcre_email(user)
    @user = user
    *@country_name = @user.country.name*
#    @state_name = @user.state.name
    email_with_name = "#{@user.first_name} #{@user.last_name} 
<#{@user.email}>"
    mail(to: email_with_name, bcc: "[email protected]", subject: 
"You have successfully created an iktusNET User Account!!")
  end

Here is the code in user_pages_spec.rb

      it "should create a user" do
        *expect { click_button submit }.to change(User, :count).by(1)*
      end

By any chance is there a possibility that I need to reset rspec somehow. 
 The tests like example 2 started failing with no code changes at 
all.  Also from time to time rspec errors would disappear with no coding 
changes.

Here are the gems I am using in my Rails application:

  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.1'
  gem 'guard-spork', '1.2.0'  
  gem 'spork', '0.9.2'
  gem 'rb-fsevent', '~> 0.9.1'
  gem 'growl'

  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '4.1.0'
  gem 'cucumber-rails', '1.2.1', require: false
  gem 'database_cleaner', '0.7.0'

Any help would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rspec/-/M-AmDjCMSJAJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to