I'm trying to write a functional test. My test looks as following:
describe PostsController do
it "should create a Post" do
Post.should_receive(:new).once
post :create, { :post => { :caption => "ThePost", :category => "MyCategory" } }
end
end
My PostsController (a part of it actually) looks as following:
PostController < ...
When you use the its method in rspec like follows its(:code) { should eql(0)} what is 'its' referring to.
I have the following spec that works fine
describe AdminlwController do
shared_examples_for "valid status" do
it { should be_an_instance_of(Api::SoapStatus) }
it "should have a code of 0" do
subject.code.should eq...
I am trying to mock a view helper with rspec2. The old way of doing this throws an error, complaining the template object is not defined:
template.should_receive(:current_user).and_return(mock("user"))
Am I missing something here, or is this not implemented in rspec2 (yet)?
...
By default, "rake specs" re-creating my test database, using environment's one.
It removes all the data, but not the the auto_increment. So when i'll try to make a new user:
User.blueprint do
login { Sham.login }
email { Sham.email }
end
# the test:
user = User.make
user.id.should == 1
It says, that ID was 1800 (auto_increment w...
When I run ./script/generate scaffold Whatever, it creates ActionController::TestCase tests for me, but I prefer to use RSpec. Is there any way to get it to generate some default RSpecs for my new class instead?
...
Hi!
I'd like to spec the fact that my application layout view prints out flash notices. However the following code does not run, the flash method does not exist in view specs (as opposed to controller specs where it works perfectly):
describe 'layouts/application' do
it "renders flash notices" do
flash[:notice] = "This is a notic...
I am having trouble building a gem. When I run rake it gives the the following error message:
You need to install rspec in your base
app
I'm not completely certain what I should be doing to fix this. I have double checked that rspec is, in fact installed. Any help would be appreciated.
...
Has anyone tried creating end user (potentially online, potentially to be printed) help/documentation out of your cucumber scenarios? Or taken screenshots for use in documentation using RSpec and Selenium RC's ability to do so?
For Cucumber, I'm imagining something like:
Scenario: If you want to add a link
Given I am on the edit blog p...
Hi,
I am really missing heavily the ability to test Views independently of controllers. The way RSpec does it.
What I want to do is to perform assertions on the rendered view (where no controller is involved!). In order to do so I should provide required Model, ViewData and maybe some details from HttpContextBase (when will we get rid ...
I have a rspec mocked object, a value is assign to is property. I am struggleing to have that expectation met in my rspec test. Just wondering what the sytax is? The code:
def create
@new_campaign = AdCampaign.new(params[:new_campaign])
@new_campaign.creationDate = "#{Time.now.year}/#{Time.now.mon}/#{Time.now.day}"
if @new_campaign.save...
Hello,
I'm pretty new to the whole JRuby world. I'm using RSpec on a pretty big test suite. I'd like to be able to run the specs frequently but the JVM takes so long to startup it's becoming a real time drain.
Is there a way to keep the JVM running? or a way to get specs to run faster with JRuby?
Thanks in advance for the help,
JPoz
...
I'm trying to mock a class method with rspec:
lib/db.rb
class Db
def self.list(options)
Db::Payload.list(options)
end
end
lib/db/payload.rb
class Db::Payload
def self.list(options={})
end
end
In my spec, I'm trying to setup the expectation Db::Payload.list will be called when I call Db.list:
require 'db/payload'
d...
I'm try to write a spec for a named scope which is date dependent.
The spec:
it "should return 6 months of documents" do
Date.stub!(:today).and_return(Date.new(2005, 03, 03))
doc_1 = Factory.create(:document, :date => '2005-01-01')
Document.past_six_months.should == [doc_1]
end
The named scope in the Document model:
name...
Hi there,
I'm trying to run the following spec:
describe UsersController, "GET friends" do
it "should call current_user.friends" do
user = mock_model(User)
user.should_receive(:friends)
UsersController.stub!(:current_user).and_return(user)
get :friends
end
end
My controller looks like this
def friends
@f...
I'm trying to run RSpec tests straight from ruby code. More specifically, I'm running some mysql scripts, loading the rails test environment and then I want to run my rspec tests (which is what I'm having trouble with)... I'm trying to do this with a rake task. Here is my code so far:
require "spec/autorun"
require"spec"
require "spec/r...
Hi All
I am having a problem in RSpec when my mock object is asked for a URL by the ActionController. The URL is a Mock one and not a correct resource URL.
I am running RSpec 1.3.0 and Rails 2.3.5
Basically I have two models. Where a subject has many notes.
class Subject < ActiveRecord::Base
validates_presence_of :title
has_many...
I'm using tabnav plugin for Rails and I want to use rpsec to make sure it highlights properly.
describe 'account navigation links' do
it 'should have account settings link' do
get '/account/settings'
response.should have_tag("li", :text => "Account Settings")
end
it 'should be highlighted' do
get '/account/settings'
resp...
I'm trying to recreate a race condition in a test, so I can try out some solutions. I find that in the threads I create in my test, ActiveRecord always returns 0 for counts and nil for finds. For example, with 3 rows in the table "foos":
it "whatever" do
puts Foo.count
5.times do
Thread.new do
puts Foo.count
...
I'm writing a RubyGem that can raise an ArgumentError if the arguments supplied to its single method are invalid. How can I write a test for this using RSpec?
The example below shows the sort of implementation I have in mind. The bar method expects a single boolean argument (:baz), the type of which is checked to make sure that it actua...
I'm pretty new to the world of RSpec. I'm writing a RubyGem that deals with a list of files within a specified directory and any sub-directories. Specifically, it will use Find.find and append the files to an Array for later output.
I'd like to write a spec to test this behaviour but don't really know where to start in terms of faking a...