Skip to content

Instantly share code, notes, and snippets.

@manusajith
Last active December 20, 2015 12:29
Show Gist options
  • Save manusajith/6130924 to your computer and use it in GitHub Desktop.
Save manusajith/6130924 to your computer and use it in GitHub Desktop.
received unexpected message :should_recieve with (:update_attributes) -Rspec error for update action
Failure/Error: scheme.should_recieve(:update_attributes).and_return(scheme)
Double "Scheme_1023" received unexpected message :should_recieve with (:update_attributes)
Failure/Error: scheme.should_recieve(:update_attributes).and_return(scheme)
Double "Scheme_1023" received unexpected message :new with (no args).
describe "update a scheme" do
before { Scheme.stub(:find).and_return(scheme) }
it "find the requested scheme" do
scheme.should_recieve(:update_attributes).and_return(scheme)
put :update, id: scheme.id, scheme:scheme
end
context "with valid scheme details" do
before { scheme.stub(:update_attributes).and_return(true) }
it "displays success message" do
put :update, id:scheme.id, scheme:scheme
flash[:notice].should_not be_nil
end
it "redirects to index page after update" do
put :update, id:scheme.id, scheme:scheme
response.should redirect_to portal_schemes_path
end
end
context "with invalid attributes" do
before { scheme.stub(:update_attributes).and_return(false) }
it "error message must be displayed" do
put :update, id: scheme.id, scheme:scheme
flash[:error].should_not be_nil
end
it "renders the edit form" do
put :update, id: scheme.id, scheme:scheme
response.should render_template(:edit)
end
end
end
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
ENV['RAILS_ENV'] ||= 'test'
# Mongoid models reload
require 'rails/mongoid'
Spork.trap_class_method(Rails::Mongoid, :load_models)
# Routes and app/ classes reload
require 'rails/application'
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
Spork.trap_method(Rails::Application, :eager_load!)
# Load railties
require File.expand_path('../../config/environment', __FILE__)
Rails.application.railties.all { |r| r.eager_load! }
# General require
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'database_cleaner'
RSpec.configure do |config|
config.mock_with :rspec do |configuration|
configuration.syntax = [:expect, :should]
end
# Clean up the database
config.before(:suite) do
DatabaseCleaner[:mongoid].strategy = :truncation, {:except => %w[users] }
end
config.before(:each) { DatabaseCleaner.clean }
end
end
Spork.each_run do
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir.glob(File.dirname(__FILE__) + "/factories/*").each {|factory| require factory }
FactoryGirl.reload
I18n.backend.reload!
Dir[Rails.root.join('spec/views/**/*.rb')].each {|f| require f}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment