similar to: some fun functionality for all your specs

Displaying 20 results from an estimated 700 matches similar to: "some fun functionality for all your specs"

2007 Mar 29
21
a better "should have valid associations"
This is pretty much the same as last time around, if you recall. Thanks to Wilson for converting to the new form. I''ve added a few lines. Basically, it iterates over your model associations and does two things. - First, just try to call the association. Usually fixes speeling erors or other such silliness. - Second, try to find a record with an :include on the association. This
2010 Jun 20
10
RSpec 2 view example: render_template
On http://github.com/rspec/rspec-rails under "View specs" there''s an example describe "events/index.html.erb" do it "renders _event partial for each event" do assign(:events, [stub_model(Event), stub_model(Event)]) render view.should render_template(:partial => "_event", :count => 2) end end Is this indeed correct? From the
2006 Dec 31
2
what''s with the response.should_be_xxxx stacktrace?
If I do get :index response.should_be_success I get about 20k of marshalled dumpage that starts like #<ActionController::TestResponse:0x390443c @body=\"<html><body>You are being <a href=\"http://test.host/carts/1\">redirected</a>.</body></html>\", @assigns=[], @redirected_to={:action=>\"show\", :id=>1},
2008 Jun 24
1
Suggestions on how to use stub_model with webrat?
Hi all, I am using story runner with webrat, but I am not sure how to incorporate stub_model into my tests. The webrat steps only care about the user interface and have nothing to say about interaction with the database. Following Ben Mabey, I have a line in my story like: "When clicks the Create button" And a step like: When "clicks the $button button" do |button|
2008 Aug 26
9
stub_model() and ActiveRecord Associations
Hi all, I have what I thought was quite a simple requirement but something to do with the way ActiveRecord''s associations work is making it quite puzzling. I guess I can sum it up with this failing test: before(:each) do @source_comment = @source.comments.create(:user_id => 1) @target_comment = @target.comments.create(:user_id => 1) end
2007 Aug 17
4
should_receive, used in the wrong place?
What do you guys think of this: if someone calls should_receive outside of an "it" block, it warns you. before(:each) do @foo = Foo.new @foo.should_receive(:monkeys) end would warn you that you''re setting an expectation in the wrong place, and that "stub" is correct when setting up objects. Opinions? courtenay
2006 Jun 08
3
Relationship and reflection
Hello, I have a question. I would like to know if there is a way with the reflection and respond_to? to know if there is a relationship between tables. When I say that I mean if inside a model there is a Has_many or belongs_to declaration. Because I try to get this information dynamically, during the execution of a script. If someone has an idea even if it''s not with the reflection,
2011 May 27
14
[rails] undefined method `model_name' for NilClass:Class
Never seen the error above before, code: describe "edit action" do it "edit action should render edit template" do food = Food.create(:name=>''mooo'') # Food.any_instance.stubs(:valid?).returns(true) get :edit, :id => food.id response.should render_template(:edit) end end -------------- next part
2011 Jan 30
5
Named routes problem... more rails than rspec
Howdy, I have emailed before about the inconsistencies I''m spotting when using named routes/resource, but I think I''ve narrowed down the issue. It would seem this has nothing to do with rspec per se, but more with how routing works with rails. If you have an object instance, that isn''t saved and you attempt to generate a path for that item, even though the item may
2008 May 26
7
Mocking Models in Controller Specs...
I find myself doing this kind of thing a lot in Controller Specs: @vacancy = mock_model(Vacancy) @vacancy.stub!(:reference) @vacancy.stub!(:title) @vacancy.stub!(:created_at) @vacancy.stub!(:updated_at) @vacancy.stub!(:body) @vacancy.stub!(:contract) @vacancy.stub!(:location) @vacancy.stub!(:salary) @vacancy.stub!(:benefits)
2006 Dec 30
1
redirect_to(:action => ''foo'') and return
I''m not sure why this is happening, but if I do this in a controller unless @variation && @variation.quantity > 0 flash[:error] = "Sorry, that product is currently not available." redirect_to(:action => ''error'') and return end rspec tells me 2) ActionController::DoubleRenderError in ''The Carts controller with an
2008 Jun 28
19
Stopping example execution?
Hello, I''m wondering If I am missing something here when creating an example that sets an expecation at the top or beginning of an action but requires you to stub / mock everything that follows. Example: I want to test that a certain controller is running a before_filter...thats easy: - controller.should_receive(:require_user) - do_get But now i''ve got to mock / stub
2007 Jun 12
3
rspec 1.0.x and liquid?
Is anyone else using liquid with the > 1 rspec? This seems to fail: it ''should render show'' do response.should render_template(''buyers/show'') get :show, :id => 1 end with an error like 1) NoMethodError in ''/buyer GET should render show'' You have a nil object when you didn''t expect it! The error occurred
2012 Jan 17
4
Find all association methods
Hi all, I want to get all association methods in one single model.... Any default method is provided by Active Record ??? i am using ruby 1.9.3 and rails 3.1.3 Please reply me .... Thanks, kingston.s -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to
2007 Feb 13
7
Specs of code that use Time.now
Hi Just trying to spec a Rails model that defaults a valid_until date to this time tomorrow. I''ve done something similar involving Dates, and you can stub the :today method to return something fixed. But when I tried this with Time, I found that RSpec calls Time.now four times per spec. So there''s no way to spec code like 1.days.from_now . The best I can come up
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 Jan 05
4
How To Spec Controllers with Finders
Given this code (which renders rjs), I''m faced with the fixture- driven way of spec-ing or mocking. How the heck to you mock this so the code at line (2) and (4) work right? I''m still struggling with mocks but it seems like this can be done. Forgive the naivety of this question. 1. def change_quantity 2. @line_item = LineItem.find_by_id(params[:id]) 3. unless
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
I want to find out what are the associations with another active record class. So If my class is as below: Class Component < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :component end and then I do Component.reflections[:branches].active_record I would expect that to be Branch but it is in fact Component. The inspection of
2007 Aug 14
2
Finding a models asscoations
Hi, I cant seem to find the answer to this anywhere so any help/advice is appreciated. Each project has one risk and a risk has a number of has/one belongs to assocations. So what i want to do is in my code loop through all the associations for a risk and display some field information from each as they are pretty similar. So somehting like <% for model_association in project.risks %>
2011 Nov 18
1
What does :count actually mean in assert_select?
Hi guys, I tried reading up the RSPEC Book (Dec 2010) and googled a bit but I could not find anything. I''m using Rspec2. Example: spec/factories/categories.rb ====================== FactoryGirl.define do factory :category_intakes, :class => ''category'' do name ''intakes and filters'' description ''airfilters and