I'm running rails 3.0, rspec 2.0 and factory_girl. Here is the simplified scenario I'm working with: a user can subscribe to only one plan at a time
# user.rb
class User < ActiveRecord::Base
has_one :plan
attr_accessible :login, :plan_id
end
# plan.rb
class Profile < ActiveRecord::Base
attr_accessible :plan
end
# user_factory.rb...
Hi, trying to learn ruby on rails at the moment and currently learning about testing. The tutorial I'm following uses rspec, so I ran the commands:
sudo gem install rspec
sudo gem install rspec-rails
script/generate rspec
only to get an error message "Couldn't find 'rspec' generator". I've searched for an answer on this topic but I ca...
I'm building an app in rails 3 using rspec 2 for specs. All my specs are working fine, except my request spec (only have one at the moment, as I'm building specs as I work):
def mock_account(stubs = {})
@mock_account ||= mock_model(Account, stubs).as_null_object
end
before (:each) do
Account.stub(:find_by_id).with(1) { mock_account...
I'm know CruiseControl.rb used for Continuous Integration but it Prerequisites ruby 1.8.6. please sugguest me a lib sloved for all version ruby. Thanks
http://cruisecontrolrb.thoughtworks.com/documentation/getting_started
...
I need to test two things:
that certain old paths are correctly redirected to certain new paths
that the redirect is a 301, not a 302.
I'm using Capybara for my acceptance tests, but that can't handle #2. I can test that the redirect happens, but it happens silently, so I can't see that it was a 301.
Controller tests can't handle #...
I have a rails3 app that has some observers. I can't for the life of me figure out how to turn these off for my rspec tests!
...
rails 3
rspec-rails 2
in controller
def index @users = User.paginate
:page => params[:page],:per_pae => 5
end
in view User list <%
@users.each do |user|% <%=
user.name %> <% end %> <%=
will_paginate @users %>
Now I use rspec-rails 2 to test view.
require 'spec_helper'
describe "/users/index.html....
I want to write a rspec test that tests if correct layout is used for controller. (Actually I want to test that no layout is used :) ).
I did some googling and also Looked here http://stackoverflow.com/questions/109284/testing-rendering-of-a-given-layout-with-rspec-rails
But all of this does not work for Rails3.
I have used:
controll...
I'm fairly new to RoR and recently started learning BDD/Rspec for testing my application. I've been looking for a way to spec an AJAX request, but so far I haven't found much documentation on this at all.
Anyone know how to do this? I'm using rails 2.3.8, rspec 1.3.0 and mocha 0.9.8 for my stubs (which I'm also in the process of le...
I'm running through Michael Hartl's Rails Tutorial.
I'm trying to verify the title of my page. The test looks like this:
it "should have the right title" do
get 'home'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home")
end
The HTML head section looks like this
<head>
<...
I have a PathsHelper that overwrites foo_url and foo_path by processing additional parameters as well as the context from the current url. This is included in ApplicationController.
Right now, I have:
describe ApplicationController do
describe "#foo_url" do
...
end
describe "#foo_path" do
...
end
end
I'm wondering w...
I'm new to testing and rails but i'm trying to get my TDD process down properly.
I was wondering if you use any sort of paradigm for testing has_many :through relationships? (or just has_many in general i suppose).
For example, i find that in my model specs i'm definitely writing simple tests to check both ends of a relationship for r...
In a bunch of rspec rails unit specifications I do something like:
describe Foo do
[:bar, :baz].each do |a|
it "should have many #{a}" do
Foo.should have_many(a)
end
end
end
For cleaner code I'd rather do something like:
describe Foo do
spec_has_many Foo, :bar, :baz
end
So how do I write a helper method like spe...
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...
Hello,
I'm working on a Rails app.
I want to test with rspec my method "start!" of my model Backup.
So here the specs (all are methods, too):
Backup should copy files to folder /backups
Backup should check md5 sum
Backup should delete original files
For my tests, I create fake files, based on fixtures :
MyFile.all.each{|r| system(...
Same question, but solution did not work:, I've tried several versions of rspec:
http://stackoverflow.com/questions/3517724/rspec-is-giving-an-error-with-my-layout-links-from-the-rails-tutorial-failure-e
dpalacio:sample_app dpalacio$ rspec -v
2.0.0.beta.18
dpalacio:sample_app dpalacio$ rspec spec/
controllers/ factories.rb models/...
I am writing an rspec for an address model that has a polymorphic attribute called :addressable. I am using factory girl for testing.
This model has no controller because I do not wish to create a standalone address but that doesnt stop the rspec from creating a standalone address. My model, factory and rspec are
class Address < Act...
Guys,
Here is a model that I'm using, I've simplified it a bit down to the simplest form that still fails my example:
class User < ActiveRecord::Base
after_create :setup_lists
def setup_lists
List.create(:user_id => self.id, :name => "current")
List.create(:user_id => self.id, :name => "master")
end
end
And I'd like t...
I want to spec a Sinatra server that receives HTTP requests, stores things in MongoDB, and responds with JSON. How would I spec both the MongoDB entries and the responses?
I'd like to use Cucmber and RSpec to do this cause I hear they're hot, but I'm not really good with them yet.
Thanks!
Matt
...
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 => ...