rspec2

Something wrong in my sequence of factory creation..

I was hoping someone would spot why this wouldn't work. I am getting an error thats being called because the attributes I specify with Factory_Girl are not being applied to the stub before validation. The Error: undefined method `downcase' for #<Category:0x1056f2f60> RSpec2 it "should vote up" do @mock_vote = Factory.create(:vote...

Generators with rails 3 and rspec 2

I installed rails 3 with rspec 2, but when i run controller generator it creates rspec tests only for controller helpers and does not create them for controller itself. ...

Learning how to spec..seem to be having troubles

Here's my code I'm spec'ing: def vote_up get_vote @vote.value += 1 unless @vote.value == 1 @vote.save respond_to do |format| format.js { render :action => "vote", :layout => false } end end Seems pretty straightforward. This is what I'm trying to spec it with : it "should vote up" do @mock_cat = Factory.create(:ca...

undefined method `each' in a factory_girl / rspec2 scenario

I'm trying to Factory a Post associated with a Vote. So that Post.votes would generate the Vote's that are associated with it. Factory.define :voted_post, :parent => :post, :class => Post do |p| p.association :votes, :factory => :vote end And my rspec2 is relatively straightforward : describe "vote scores" do it "should show me t...

Why isn't rspec generating specs for controllers?

Created a new app with rails generate new_app -T and ran rails generate rspec:install. $ rails generate controller Test foo bar create app/controllers/test_controller.rb route get "test/bar" route get "test/foo" invoke erb create app/views/test create app/views/test/foo.html.erb crea...

Why is capybara/rspec loosing the current_user?

The following Spec is failing and failing over again. I've tried everything but can't get it to work. If I test it manually all looks fine :( Some help/tips would be really nice! The join-action should add an logged-in user to an guild/group if he/she got the right token (in the url). If the user isn't logged in the action redirects to ...

response.should have_text leads to undefined method `has_text?'

I would like to test a controller that directly renders some JSON output (by using "render :json => @entity_names"). For that task I tried in my spec file "response.should have_text('["enim", "enita"]')". Unfortunately I always get that error: Failure/Error: response.should have_text('["enim", "enita"]') undefined method `has_text?' for ...

Turn off transactional fixtures for one spec with RSpec 2

How do I turn off transactional fixtures for only one spec (or Steak scenario) with RSpec 2? I tried some things found on the web without any success. This leads to an undefined method exception. describe "MyClass without transactional fixtures" do self.use_transactional_fixtures = false ... end This simply does nothing (transac...

RSpec-2 and Devise

Hi, i create a customized devise registration controller and i want to test it with rspec. I've tried it with a very simple test : it "creates a new parent" do Parent.should receive(:new) post :create end but i get this exception: Failures: 1) Parent::RegistrationsController POST create creates a new parent Failure/Error:...

Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs before(:all) do ActiveSupport::TestCase.use_transactional_fixtures = false end after(:all) do ActiveSup...

Stubbing all views in a config.before block in RSpec2, Rails3

I have this in my spec_helpers.rb file: config.before(:each, :type => :view) do @widget = Factory(:widget) view.stub!(:widget => @widget) end @widget is accessible in my views, but the view.stub! part returns: undefined method `_routes' for nil:NilClass /Users/mdarby/.rvm/gems/[email protected]/gems/activesupport-3.0.0...

Why does rspec redirect not get full route during test?

I'm attempting the following functional test on the controller. I'm using the following RSpec2 Rails 3 Shoudla Mocha Here's the test context "POST on create should be successful" do before(:each) do Model.any_instance.expects(:save).returns(true).once Model.any_instance.stubs(:id).returns(1) post :create, :model => {}...

NoMethodError in Users#show

I'm following the rails tutorial @ http://railstutorial.org On chapter 11, I'm having issues with showing microposts from users. Based on the tutorial, the RSPEC test should pass. However, it fails 1) UsersController GET 'show' should show the user's microposts Failure/Error: get :show, :id => @user undefined method `model_name'...

RSpec nested-model in view spec

I am trying to write a view spec to drive out a form with a nested model. In my example every Organization has many Users. When you create a new organization you create the first user at the same time. This part works: require 'spec_helper' describe 'organization/new.html.erb' do let(:organization) do mock_model("Organization")....

Perfecting an RSpec macro for controllers

I'm trying to generate an easy macro for a Rails app that uses Devise for authentication. Basically I want to ensure that when a user accesses a page that requires authentication, they're redirected to the login page. So something like this: it_requires_authentication_for :index, :new, :create, :update The desired results here shoul...

Test the render method in a controller with RSpec

I am trying to test the render method in a controller with RSpec (2.x). Here the code in my controller: respond_to do |format| format.html # index.html.erb format.json { render :json => @entities, :include => :properties, :overview => options[:overview] } end And here the test I try in my spec file: controller.should_receive(:r...

How to test link_to_unless_current in RSpec view example group

I'm learning RSpec 2 with Rails 3 and while it's been going along quite nicely so far, I'm having a problem testing the helper link_to_unless_current in a view. What I've been trying to do is use a simple assert_select from a view spec to determine if a link is being generated in the following partial view (HAML): %article.post{ :id => ...

howto spec not all models

I know rake spec:models to spec all models. Is there a way to spec only one model, or only a given collection of models? Something like this would be desirable: rake spec:model user or with a collection of models rake spec:model user role order BTW: Brian Hogan wrote created something similar (see here) but maybe there is some...

How do I test the title of a page from an RSpec view spec?

I'm learning RSpec 2 with Rails 3. In order to set the contents of the tag in the layout for each page, I have a helper that can be used to set the title and then return it: def page_title(subtitle=nil) if @title.nil? @title = ["Site Name"] end unless subtitle.nil? @title << subtitle end @title.reverse.join " - " en...

Factory Girl: How to associate a record to another record without creating a new record?

Hello. I'm using Factory Girl/Rspec2/Rails 3. In factories.rb, I have: Factory.define :user do |user| user.name 'Some guy' user.email '[email protected]' user.password 'password' end Factory.define :org_admin, :parent => :user do |user| user.email '[email protected]' end Factory.define :user_with_memb...