search for: mock_model

Displaying 20 results from an estimated 137 matches for "mock_model".

2007 Oct 06
4
spec''ing views, mock_model associations
...l players" do render :partial =>"games/game", :object => @game response.should have_tag(''a'',"(2) Players") end I''m not sure how to do the mock model, I think it would be done two ways but unsure of the syntax: 1: add players in @game = mock_model(Game, :name => ''The Battle for Blaze'', :salt_grains => ''5000000'', :people => ''5000000'', :days => nil, :created_at => "Mon Oct 01 00:02:44 -0400 2007", :enabled => true, :players => { }) 2: assign...
2007 Jul 18
5
Mocking Rails association collections
Rails model association collections allow you to do nifty things like: article.comments.find(:all, :conditions => {:created_at > 1.day.ago}) Has anyone found a good way to mock this up? I''m currently doing this: @comment1 = mock_model(Comment) comments = mock(Array) comments.stub!(:find).and_return([@comment1]) @article = mock_model(Article) @article.stub!(:comments).and_return(comments) I don''t like this, because of that intermediate ''comments'' object, whose only purpose is so that i can st...
2007 Jul 05
6
mocking methods in the controller.
Hi, I''m very new to rspec so please be patient with me. I''ve tried to take some of my tests out of the controller specs to check for things that are rendered. This has not worked so well, since my views have the controller method current_user in quite a few places. Is there any way that I can define this so that my views will be executed? Will this same thing occur for all
2007 Dec 05
9
Does mock_model''s :null_object option work?
...struct and don''t have the time to refactor nicely right now. I''m just trying to get past the untested/un-speced cruft quickly to write the spec for my new code, so I''m looking for expediency over prettiness. I''m specifying before( :each ) do @order_address = mock_model( OrderAddress, :null_object => TRUE ) end but finding that unstubbed/unmocked method calls on @order_address still throw error messages like: Mock ''OrderAddress_1026'' received unexpected message :first_name with (no args) so I''m starting to wonder whether the :null_...
2012 Aug 03
1
Mock_model not recognizing act_as_mappable
I am using mock_model in my tests, and I encountered a situation where my stub is failing. Here''s the scenario: Controller: @locations = Location.al(:bounds=>bounds)l @locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng]) Rspec: @location = mock_model(Location) Location.stub(:...
2007 Aug 30
7
mock_model in spec/lib
Has anyone else run into a problem with trying to use mock_model in spec/lib ? For some reason, I can take the same spec, put it in spec/models, have it run fine, but put it in spec/lib, and have it complain about not being able to find #mock_model Thanks, Edward
2007 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model? I''m assuming i need to say @mock_thing = mock_model(Thing) @mock_thing_errors = mock("errors") @mock_thing_errors.should_receive(:full_messages).and_return("An error") @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) Just wanted to check the best practice on this kind of thing and how other people handle it....
2007 Aug 19
4
describing a mock_model as being an instance
Is there a built-in way of describing a mock_model as being an instance, beyond stubbing the eval("Object.methods - Object.new.methods") methods to throw NoMethodErrors? Edward
2007 Oct 05
7
Easy AR association stubbing
I''ve added a method to the mock class that makes it pretty easy to stub associations in rails. I''ve been using it for awhile and it seems to cut down on a lot of setup code for the controller and model specs that use associations. #before @person = mock_model(Person) posts = mock(''post_proxy'') posts.stub!(:build).and_return(mock_model(Post, :save => true)) @person.stub!(:posts).and_return(posts) # now @person = mock_model(Person) @person.stub_association!(:posts, :find_by_title => mock_model(Post)) Just add this to the spec h...
2008 May 20
4
mock_model not stubbing model attribtues in view spec
Hi -- I am just getting to grips w/ view specs, and am having an issue with mock_model not stubbing the mocked model''s attributes. For instance, I have the following: <CODE> before do @input_timesheet = mock_model( InputTimesheet ) assigns[:input_timesheet] = @input_timesheet end it "should display a table element" do render ''/input_timeshee...
2007 Oct 12
3
Strange mock_model behaviour with ActiveResource model
Hi, I have two models in an app that inherit from ActiveResource::Base. The scaffold controller tests for one of the models works fine, but the other one dies when calling mock_model in the "handling GET /fa_codes" spec: Specifically, the call to mock model here: before do @fa_code = mock_model(FaCode) FaCode.stub!(:find).and_return([@fa_code]) end generates this failure: NameError in ''FaCodesController handling GET /fa_codes should assign the...
2007 Nov 21
7
describe AddressesController, "handling GET /addresses" do
...respond_to do |format| format.html # index.html.erb format.xml { render :xml => @addresses } end end private def get_company @company = Company.find_by_id(params[:company_id]) end My controller spec code for handling GET /addresses: before do @company = mock_model(Company) @addresses = mock("addresses") @company.stub!(:addresses).and_return(@addresses) Company.stub!(:find).and_return(@company) end def do_get get :index, :company_id => 1 end it "should be successful" do do_get response.should be_success...
2007 Jun 07
4
checking associated objects have been deleted
...I have specified the association as a dependent one. the only way I can think of is to use fixtures (or create real associations in the before callback) and then check that they have been deleted using Taggings.count(). Can it be done using mocks instead? describe Book do before do @book = mock_model(Book) @tagging = mock_model(Tagging) @book.stub!(:taggings).and_return([@tagging, @tagging]) end it "should delete associated taggings when destroyed" do end end thanks dave
2007 Sep 29
1
mock_model named spaces not working
I have a namespace called saltmines The following will fail the spec @player = mock_model(Saltmines::Player) 1) ActionView::TemplateError in ''/saltmines/players/index.rhtml should render list of saltmines/players'' You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each On line...
2009 Feb 25
2
How to properly mock a complex object "comment.initiator.group.name"?
I am wondering what is the best way to mock such expression: "comment.initiator.group.name" What I do now is: =========================== comment = mock_model(Comment) initiator = mock_model(User) group = mock_model(Group, :name => "Admin") initiator.stub!(:group).and_return(group) comment.stub!(:initiator).and_return(initiator) =========================== So it becomes quite complex when the length of the expression increases. Is it possi...
2007 Jul 24
4
Possible Bug
...strange failure Mock ''Book_1027'' expected :store_with_privacy? with (#<Clip:0x1a99b96 @name="Clip_1025">) but received it with (#<Clip:0x1a99b96 @name="Clip_1025">) The Spec it "should check that a book can save a clip" do @user = mock_model( User, :id => 3 ) @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => @user ) @book = mock_model( Book, :id => 2, :privacy => :public, :user => @user, :user_id => @user.id ) @book.should_receive( :store_with_privacy? ).with( @clip ) clipping...
2007 Apr 20
5
stubbing with and without a string
What is the difference between these two ways of mocking (with and without the string): mock(''Object'') and mock(Object) ? Scott
2007 Oct 16
3
Controller iterating through returned records and appending to each
...s.empty? ? "-" : e.billablegoals.select { |bg| bg.effective_date <= Date.today }[0].goal } end Spec: require File.dirname(__FILE__) + ''/../spec_helper.rb'' describe ManagementController, "GET /management/employee_report" do before(:each) do @bg1 = mock_model(Billablegoal, :effective_date => Date.today-3.months, :goal => 50) @bg2 = mock_model(Billablegoal, :effective_date => Date.today + 1.month, :goal => 75) @mock_employee = mock_model(Employee, :billablegoals => stub(Array, :select => [@bg1], :empty? => false)) @employ...
2011 Jun 29
6
RSpec with Rails 3.1rc4: spec test won't recognize <%= %> (should be simple)
In my user_sessions_controller: class UserSessionsController < ApplicationController before_filter :require_no_user, :only => [:create, :new] before_filter :require_user, :only => :destroy def new @user_session = UserSession.new @message = "Hello." end def create @user_session = UserSession.new(params[:user_session]) if @user_session.save
2007 Nov 28
6
Newbie question
I installed Rspec and am getting the following failure: $ sudo gem install rspec Successfully installed rspec-1.0.8 Installing ri documentation for rspec-1.0.8... Installing RDoc documentation for rspec-1.0.8... $ spec -v RSpec-1.0.8 (r2338) - BDD for Ruby http://rspec.rubyforge.org/ $ cat acct.rb describe Account, " when first created" do it "should have a balance of $0"