Displaying 20 results from an estimated 4000 matches similar to: "mock_model named spaces not working"
2007 Oct 08
6
spec''in controllers request for nested routes
describe PlayersController, "handling GET /saltmines/games/1/players" do
before do
@game = mock_model(Game, :to_param => "1")
@game.stub_association!(:players, :find => mock_model(Player))
end
def do_get
get :index, :game_id => @game
end
it "should be successful" do
do_get
response.should be_success
end
it "should
2007 Oct 06
4
spec''ing views, mock_model associations
I writing a spec that returns the count of how many players in a game:
it "should how many players in a link to all 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
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))
2007 Oct 05
13
spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following
error
2)
NoMethodError in ''/games/_game.rhtml should show game name''
undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c>
/Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in
`matches?''
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
2007 Aug 21
2
using restful_authentication current_user inside controller specs
I''m using restful_authentication in my app and I have the before filters in
my application rhtml:
before_filter :login_required
around_filter :set_timezone
around_filter :catch_errors
Currently I have them commented out while rspec''in but I''ll need to add them
in my specs.
def create
@ticket = Ticket.new(params[:ticket])
@ticket.user = current_user
if
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(:all).and_return([@location])
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:
2007 Aug 17
11
[rspec] looking for a simple refresher
I''ve been off the rspec for a few months and I''m trying to get back on it.
1)
Spec::Mocks::MockExpectationError in ''TicketsController handling POST
/tickets should create a new ticket''
Mock ''Ticket_1001'' expected :new with ({}) once, but received it 0 times
./spec/controllers/tickets_controller_spec.rb:16:
script/spec:4:
class
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 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 Dec 05
9
Does mock_model''s :null_object option work?
Please understand in the following that I am making relatively minor changes to legacy (non-TDD/BDD) code in Substruct 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
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
2007 Jul 06
3
stubbing helper methods for View specs
Hi there
I have several view specs, that include the following snippet in
their "before" block to stub the methods by acts_as_authenticated
before :each do
@u = mock_model(User)
@u.should_receive(:name).and_return("Hans Muster")
template.should_receive(:logged_in?).and_return(true)
template.should_receive(:current_user).and_return(@u)
end
this
2007 Oct 01
15
how to spec views
I''m trying to spec a view but haven''t done much view specing.
This view render different partials depending on authentication of the user:
annon, admin, player
So I I''ll write if conditionals in the view with the partials
it "should render signup propaganda for annon users trying to view games"
do
render "/games/index.rhtml"
2007 Sep 10
6
RSpec view spec writing problem (unable to generate url_for in RESTful resource link_to)
Thanks, first, to everyone who''s asked and answered questions on this list,
and to the creators of RSpec - it is all very helpful. I''ve searched the
mailing list, and had a couple 2hr googling sessions that didn''t help me
find an answer.
I''ve run into a problem getting my first non-trivial view spec to run. I
get an error when trying to generate a link_to()
2007 Sep 30
9
Problems with testing nested routes using mocking
Hello forum
I have there to files
#----- virtual_host_controller.rb
class VirtualHostsController < ApplicationController
before_filter :capture_domain
# GET /domain/1/virtual_hosts/1
def show
@virtual_host = @domain.virtual_hosts.find(params[:id])
respond_to do |format|
format.html # show.rhtml
end
end
private
def capture_domain
if
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)
2007 Aug 08
25
Problems with RESTfully generated helpers
I am using helper the RESTfully generated helper methods in my views.
My routes are nested so the helpers appear to need arguments passed to
them, but it works without arguments. Say for example I have pages and
comments. If I do page_comments_path without parameters, it works.
However, when I run the rspec test, it fails and tells me i''m missing
parameters. I tried to pass
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