rspec

Problems with validates_inclusion_of, acts_as_tree and rspec

I have problems to get rspec running properly to test validates_inclusion_of my migration looks like this: class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :name t.integer :parent_id t.timestamps end end def self.down drop_table :categories end e...

Test with Rspec using session sinatra

Hi All, I have sinatra appliction using session, how do I test a page that uses session? I using Rspec + sinatra Tks ...

how to test workling/starling with rspec

Hi, I have put some tasks in my rails app over to a Workling worker - my question is, what is best practice to test the Workling class with rspec? I have set up rspec to be able to call the Workling class, (I use Sterling too), but since it is asyncron I dont know how to test for the result of the work done by workling. Thanks ...

Testing Rails Metal/Rack with RSpec?

Say I have a Metal class named Preview. How do I test it with RSpec? When I try: require 'spec_helper' describe Preview do it "should return the posted content" do post "/preview", :content => "*title*" response.body.should == "*title*" end end I get: undefined method `post' for #<ActiveSupport::TestCase::Subclass_1:0...

A simple factory_girl question

I have two factories (post_factory.rb, comment_factory.rb) in separate files. I'd like to create a bit complex factory, which will create a post with associated comments for me. I created a third file, called complex_factory.rb, and wrote the following code: Factory.define :post_with_comments, :parent => :post do |post| post.after_cre...

Testing Rails Metal With Cucumber/rSpec

Hi, I'm trying to stub a third party service that my metal talks to. It seems rspec mocks/stubs don't extend all the way to the Metal. When I call stubbed methods on objects, it calls the original one and not the stubbed one. Any idea of how I can have rSpec doubles extend all the way to the metal? Thanks. -Nash ...

Trouble mocking on cucumber + rails

I'm having a lot of trouble trying to define a mock for a rails models on cucumber. It seems like the method is creating a bunch of message expectations and i keep getting errors like these: Given I have only a product named "Sushi de Pato" # features/step_definitions/product_ steps.rb:19 unexpected invocation: #<Mock:ProductCate...

Example of a Good Func Spec?

Hey, I'm writing my func spec, and I was wondering if there are any good samples of a complete and well-written func spec? Like "This is a standard You're supposed to aspire to" type of spec. I know that Joel has a skeleteon of a func spec on his website, but I am looking for something more complete because I'm not of the appropriate am...

email-spec destroys my rake cucumber:all

At the beginning this worked fine: $ rake cucumber:all But then $ script/plugin install git://github.com/bmabey/email-spec.git remote: Counting objects: 162, done. remote: Compressing objects: 100% (130/130), done. remote: Total 162 (delta 18), reused 79 (delta 13) Receiving objects: 100% (162/162), 127.65 KiB | 15 KiB/s, done. Resolvi...

rspec install failed

screen: E:\ir\InstantRails\rails_apps>gem install rspec Attempting local installation of 'rspec' Local gem file not found: rspec*.gem Attempting remote installation of 'rspec' ERROR: While executing gem ... (Gem::GemNotFoundException) Could not find rspec (> 0) in the repository my env: InstantRails 1.3a on windows thanks for he...

How to remove duplication from RSpec

context "answer is correct" do before(:each) do @answer = stub_model(Answer, :correct => true).as_new_record assigns[:answer] = @answer render "answers/summarize" end it "should display flashcard context properly" do response.should contain("Quiz") end it "should summarize results" do response.should contain("is correct") e...

How do I change the RAILS_ENV for rspec integration or remote specs?

I would like to create a set of remote specs "specs/remote" that run with the RAILS_ENV = 'remote'. These specs need to use a different database than the model specs. I would make them integration specs if that was easiest. Ultimately, what is the easiest way change the RAILS_ENV from test and run a group of specs? ...

Generate a controller with all the RESTful functions

Hello, I am trying to generate a controller with all the RESTful actions stubbed. I had read at link text that all I needed to do was to use call the generator with just a controller name I would get just that. So, I ran "script/generate rspec_controller Properties" and I got an empty controller. Any other suggestions would be great...

Test Ruby-on-Rails controller with RSpec and different route name

I have a Rails model named Xpmodule with a corresponding controller XpmoduleController. class XpmoduleController < ApplicationController def index @xpmodule = Xpmodule.find(params[:module_id]) end def subscribe flash[:notice] = "You are now subscribed to #{params[:subscription][:title]}" redirect_to :action => :index...

What's a good tutorial for creating a gem with RSpec?

I've been searching around for ways to create a gem with RSpec, but haven't found descriptive tutorials. I started out with Ryan Bates' Making a gem, but I'm looking for a tutorial that discusses creating an acts_as style gem with RSpec. By acts_as, I mean to say that the gem adds certain methods to an existing class in Rails. Why is t...

Nested Resource testing RSpec

I have two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => "User", :foreign_key => :user_id end class User < ActiveRecord::Base has_many :solutions end with the following routing: map.resources :users, :has_many => :solutions and here is the SolutionsController: class SolutionsC...

How to verify that "puts" has been called with a certain message?

Hello there. I'm trying to make this test fail :) it "should display the question" do @ui.should_receive(:puts).with("What's your name?").once @ui.ask_question("What's your name?") end At the moment it passes even if I don't call puts in my function. ...

How to test declarative_authorization with rspec

Is there a way to test the declarative_authorization permissions with respect? In the documentation it has some instructions to use test unit, but I can't seem to find a way to use rspec. ...

Rails test db doesn't persist record changes

I've been trying to solve a problem for a few weeks now. I am running rspec tests for my Rails app, and they are working fine except for one error that I can't seem get my head around. I am using MySQL with the InnoDB engine. I have set config.use_transactional_fixtures = true in spec_helper.rb I load my test fixtures manually with th...

Why don't RSpec's methods, "get", "post", "put", "delete" work in a controller spec in a gem (or outside Rails)?

I'm not new to Rails or Rspec, but I'm new to making gems. When I test my controllers, the REST methods "get", "post", "put", "delete" give me an undefined method error. Below you'll find code, but if you prefer to see it in a pastie, click here. Thanks! Here's my spec_helper: $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.un...