How should I spec this nested build:
#projects_controller.rb
def new
@account.projects.build
end
So far I have something like this:
#projects_controller_spec.rb
describe ProectssController do
describe "GET new" do
let(:account) { mock_model(Account) }
let(:project) { mock_model(Project).as_null_object }
before do
...
I am trying to test for a comment deletion using Rspec. I think my test is wrong because when I try to delete a comment in my browser, it works.
Here is the Rspec test that I am running:
before(:each) do
@admin = Factory(:user, :admin => true)
@user = Factory(:user, :email => "[email protected]")
@article = Factory(:arti...
My users_controller.rb
# GET /users/1/edit
def edit
@user = current_user
#@user = User.find(params[:id])
end
my sweet looking users_controller_spec.rb ( notice all my commented out attempts )
describe "Authenticated examples" do
before(:each) do
activate_authlogic
UserSession.create Factory.build(:valid_user)
end
des...
In Spec::Runner::Formatter::BaseTextFormatter the method "def dump_summary(duration, example_count, failure_count, pending_count)" provides the parameter "duration" which seems to be the time it takes for all tests to execute. I would really like to know how long each test takes individually, is it possible to get this information? The m...
I have a Rails application with over 2,000 examples in my RSpec tests. Needless to say, it's a large application and there's a lot to be tested. Running these tests at this point is very inefficient and because it takes so long, we're almost at the point of being discouraged from writing them before pushing a new build. I added --profile...
Hi,
I am writing a spec for the create method of a controller :
describe "POST create" do
it "should create an adtag with valid params" do
campaign = Campaign.make
campaign_attributes = Hash.new
campaign_attributes[:adtag_attributes] = Hash.new
campaign_attributes[:adtag_attributes][:code] = "<h1>Sample co...
User.should_receive(:update_attributes).with({'these' => 'params'})
What does that statement mean? these isn't instantiated anywhere as meaning anything.
The whole statement is this :
describe "with valid params" do
it "updates the requested user" do
User.should_receive(:find).with("37") { mock_user }
User.should_re...
I am new to rails, but not to ruby, and the book I am reading (Pragmatic Programmers Agile Dev. with Rails 4th Ed.) just introduced me to unit tests in Rails. The book showed me the default rails testing suite (a subclass of Test::Unit). In the Rails community, is this the main testing framework that is used, because I use RSpec when doi...
I'm trying to test that a view was rendered with a given layout. How can I test which layout was used for the call to render() ?
...
I'm trying out 'shoulda' on top of rspec (rails 3) with the following spec:
require 'spec_helper'
describe Article do
should "be true" do
assert true
end
end
and it fails with
/Users/jeppe/.rvm/gems/ruby-1.8.7-p302/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/handler.rb:11:in `handle_matcher': undefined method...
I'm writing an rspec scenario thats failing with:
(#<User:0x1056904f0>).update_attributes(#<RSpec::Mocks::ArgumentMatchers::AnyArgMatcher:0x105623648>)
expected: 1 time
received: 0 times
users_controller_spec.rb:
describe "Authenticated examples" do
before(:each) do
activate_authlogic
@user = Factory.create(:vali...
This is a pure syntactical question. I'm very new to RSpec.
I basically want to write something on the lines of this erroring line :
controller.stub!(:current_user(:update_attributes => false))
Anyone know how to properly write that?
RSpec's default looks like this :
User.stub(:find) { mock_user(:update_attributes => false) }
...
I have a module which is used in several controllers and is stored in app/controllers/. I want to create a spec for it in spec/controllers. The spec will be testing the module's functions, not an actual controller class.
But, all specs in spec/controllers get the ControllerExampleGroup behaviors. And once that example is mixed in a con...
Hey, I'm using TDD with rails for the first time... interesting concepts. Definitely useful. That is, until I come to this. When I run my test I get:
1) User should build the full name correctly
Failure/Error: @u1.fullname.to_s.should be("#{@attr[:firstname]} #{@attr[:lastname]}")
expected Joe Smith, got "Joe Smith"
# ./spec...
I have one spec:
require 'spec_helper'
# hmm... I need to include it here because if I include it inside describe block `method_missing` exception raises.
include Shoulda::ActionController::Matchers
describe CategoriesController do
include Devise::TestHelpers
render_views
context "new should render template :new" do
setup ...
I am trying to mock out the session hash for a controller like so:
it "finds using the session[:company_id]" do
session.should_receive(:[]).with(:company_id).and_return 100
Company.should_receive(:find).with(100)
get 'show'
end
When I call get 'show' it states:
received :[] with unexpected arguments
expected: (:company_id)
...
Hey Guys!
I am trying out rails3. I am using railstutorial
site to explore more about rails3; the tutorial is very good to begin with (I have minimal experience with rails2).
I have an issue with rspec which is currently blocking my progress. I saw that the tutorial recommended using rspec2.0.0.beta.18 gem; I instead installed rspec2.0...
My friends and I are working on some basic Ruby exercises to get a feel for the language, and we've run into an interesting behavior that we're yet unable to understand. Basically, we're creating a tree data type where there's just one class, node, which contains exactly one value and an array of zero or more nodes. We're using rspec's...
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...
I'm using rspec and I'm trying to test whether or not my model y has many x. I've tried all sorts of things, including looping through the methods array, and can't seem to find a good method online. So what should I use?
...