Displaying 20 results from an estimated 1000 matches similar to: "can''t access helper methods for model testing"
2007 Dec 11
3
Transactional/Rollback problems
I''m having a rollback problem with rspec trunk. It doesn''t seem like
rollbacks are happening quite as often as they should be. It
appears as though the rollbacks are *NOT* occurring on the first
description block in a file, but are for the rest. Here is a set of
specs that are failing:
require File.dirname(__FILE__) + "/../spec_helper"
describe
2007 Nov 20
3
How to test views with Nested Resources and Partials
Hi everyone,
I am relatively new to rspec and I am running into a wall in testing my
views. I have a RESTful resource Contracts with a nested resource of
Line_items.
I am trying to figure out how to test the "edit" form of the Line_items.
What complicates this is the nested routing and how to account for it,
and that there is a partial form (_form.haml) that both the edit.haml
and
2008 Jan 28
2
Could this controller test be made simpler?
In a create controller method I am testing the else clause that occurs
when the model is unable to be saved. Sounds simple enough, but because
model is created before the save and the form has to be re-filled I now
have to stub a model and all the attributes. Since the error messages
are displayed I also have to stub some methods within the model that
allow the error messages to be displayed
2007 Apr 30
4
Mocking with Calculated Results
I am setting up an AR mock object and wanted to sanity check it. My
intent is to mix this into all my examples and then override/add
methods where necessary. Note that I''ve anticipated three cases for
find:
find with one numeric argument => object
find with :all => Array
find with anything else => nil
This roughly approximates how ActiveRecord::find works in this case
2007 Jul 12
3
Agh, this is annoying. Why is this happening?
My problem:
Mock ''Task_1005'' received unexpected message :user_id= with (1)
No matter what I do to try to stub that out it will still fail out and give
me that message.
Here is my spec
describe TasksController, "handling POST /tasks" do
before(:each) do
@task = mock_model(Task, :to_param => "1", :save => true)
2007 Apr 19
5
Best practice thoughts: Model helpers, mocks
Hello! I''m pretty new to unit testing, and have only been using RSpec
for a few weeks. I found that for my controller specs, my setup
methods were getting very long building mocks/stubs for all the model
objects I needed to work with.
I''ve started creating helpers like the following for each of my
models. The "min_" methods are short for "minimum", and
2008 Jan 30
2
Stubbing controller methods vs model methods
I had an error that I couldn''t figure out, then when writing up a
question for the forum I figured it out. The thing is I don''t
understand why the change that was made works and why what existed
before didn''t.
Here is the initial post when I had the error:
----------------------------------
In the controllers/application.rb file
I have a method that finds the account
2007 May 23
2
rspec mocha and controller specs without integrated_views
The ability to choose a mocking framework is great as I prefer mocha, but I
am have problems.
On my controller specs, I am forced to ''integrate_views'' as the following
code below shows you, the mocking of views is rspec specific. See stub!
versus mocha''s stub
unless block_given?
unless integrate_views?
2007 May 20
9
How to test for exceptions
Hi folks,
I''m in the process of converting a Test::Unit functional test to RSpec, but I''ve run into a slight problem. I tried looking through the documentation but I still don''t know what I missed.
Thanks in advance,
Blake
describe VenuesController, "on update" do
before(:each) do
@venue = mock("venue")
2007 Nov 01
2
Can''t use #exactly when #and_return influences it.
I want my class Reader to loop on the content of its Stack until false is
returned. I also want an optional argument to exist that limits how many
times the stack will be read, even if some elements are left. I was trying
to spec this last bit but ended up on a false positive.
Hope the example will be clear enough:
#spec_reader.rb
describe Reader do
it "should stop reading items when
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))
2009 Jan 27
2
[RSpec] Error when returning multiple values from a stub
Hey guys. I''ve just found some odd behaviour within RSpec 1.1.12 , and
would like to know whether this is a bug, or I''m doing something wrong.
When I give multiple return values to a stub, like this:
SubtitleFile.stub!(:new).and_return @sf1, @sf2
RSpec complains:
Mock ''SubtitleFile_1001'' received unexpected message :size with (no
args)
However, if I
2007 Jun 03
3
should_receive.again
Hi,
It appears that if I have 2 should_receives in a row, the latest one
overrides the previous one(s).
If there isn''t one, could we add a way to accumulate them, such as
@thing.should_receive(:method).and_return(@value)
@thing.should_receive(:method).again.and_return(@value)
@thing.should_receive(:method).again.and_return(@value)
would be equivalent to
2007 Oct 25
1
Mocking/Stubbing help with subdomain as account key
My app uses account_location to set up subdomains as account keys. In
my controllers, all my model operations are scoped through the
@current_person object.
The question is: How do I test this with RSpec''s mocking and
stubbing? Basically, I need to test that @current_person.things is
getting the find message and returning @thing. I''ve tried stubbing
and mocking
2007 Nov 01
2
Writing controller specs
One thing that is bothering me about my controller specs is that
sometimes I end up with a number of examples that are the same except
for the example name.
The reason that this happens is that I''ve expressed all the expected
behavior with should_receive. While this does more or less work as
intended it doesn''t feel right.
As an example, let''s say I''m writing
2007 Oct 26
3
Specing with Subdomains as Account Keys
How do you go about implementing and rspecing subdomains as account
keys? I''m sure that this must be an issues for others as well.
So I have an app using subdomains as account keys. The Application
Controller sets up @current_company in a before filter. Everything is
done within the context of the @current_company.
After reading about Demeter''s Revenge
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble
understanding how i should mock my user. The user has a habtm
relationship to a roles model (acl_system2 plugin), but I''m not sure
how to tell rspec about a model.
My code:
describe UsersController do
integrate_views
before(:each) do
@user = mock_model(User)
2006 Dec 18
2
should_receive and multiple return values
Hi
I just got bit by a misunderstanding about and_return.
I''ve got this controller method parse_parameters that loops over
query string parameters and parses out vehicle registration dates.
We have to turn these into one of three bands (Jan-Feb, Mar-Aug, Sep-
Dec) so I wrote a method (registration_date_to_band_year_and_month)
takes a date and returns two return values, the year
2007 May 17
4
How to mock helpers in view specs ?
Hi all,
I am mocking the following Rails view (inside a partial):
<%= render :partial => "forums/forum",
:collection => forum_category.forums.readable_by(current_user? ?
current_user : nil) %>
My spec fails with the following message:
1)
ActionView::TemplateError in ''forum_categories/index (anonymous user)
should only render forums accessible to anonymous
2007 Dec 04
10
Unexpected message on :attr_accessor
This may be a dumb noob issue, but I haven''t found any answers while seaching
the forum--
I have a controller method
def edit
@user = User.find params[:id]
@user.password_confirmation = @user.password
end
The User class has an "attr_accessor :password_confirmation" definition (so
"password_confirmation" doesn''t exist in the users table). My spec