Failure: Expected 0 to be = 1 on ruby on rails
The issue is that there is no html matching "Help | Ruby on Rails Tutorial Sample App"
.
if you look at the definition of assert_select
, it accepts :count
as (optional) argument. If the count
is not specified, it sets the minimum occurrence of the html
to 1. This is why the error you are getting is Expected 0 to be >= 1.
. In your case there were 0 matches where the test expected at least 1 match.
Expected at least 1 element matching div#error_explanation, found 0.. Expected 0 to be = 1
I guess that you are not rendering the shared/_error_messages.html.erb in your app/views/password_resets/edit.html.erb form.
<% provide(:title, 'Reset password') %>
<h1>Reset password</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user, url: password_reset_path(params[:id])) do |f| %>
# Render the error messages!
<%= render 'shared/error_messages' %>
<%= hidden_field_tag :email, @user.email %>
Make sure that this is correctly inserted and the test should be successful!
Rspec FactoryGirl :: Failure/Error expected: 1 time received: 0 times
I finally figure it out by asking help from my project manager
he quoted
LevelAccessController :
class Manage::Employments::LevelAccessesController < InheritedResources::Base
before_filter :authenticate_user!
defaults :resource_class => Employment::LevelAccess, :collection_name => 'level_accesses', :instance_name => 'level_access'
protected
def begin_of_association_chain
employment
end
def employment
@employment ||= Employment.find(params[:employment_id])
end
end
so i change the rspec which
describe 'Get id to Show' do
it "should find the correct value to show" do
Employment::LevelAccess.should_receive(:find).with(@level_access.id.to_s).and_return(@level_access)
get :show, :employment_id => @employment.id, :id => @level_access.id
end
end
into
it "should find the correct value to update" do
@employment.level_accesses.should_receive(:find).with(@level_access.id.to_s).and_return(@level_access)
put :update, :employment_id => @employment.id, :id => @level_access.id
end
since the begin_of association_chain relation in controller should have make the instance available for relation chaining in the rspec.
Related Topics
How to Override [] Brackets in Ruby
Is It Ever Necessary to Use 'Chomp' Before Using 'To_I' or 'To_F'
Capistrano and API Keys in Env Variables
How to Get Http Headers Before Downloading with Ruby's Openuri
Undefined Method (Nomethoderror) Ruby
How to Do String Comparison in Ruby
How to Get Long Filename from Argv
Execjs and Could Not Find a JavaScript Runtime
Rails 3.1 Load CSS in Particular Order
How to Use Reference Images in SASS When Using Rails 3.1
Issues Installing Ruby and Rails and Devkit on Windows 7 X64 - Fix Needed
How to Preserve Case with Http.Get
Camelcase Column in Postgresql Database in Rails (Activerecord)