I'm using rr (the mocking framework) and rspec with ruby-on-rails. Also, I'm using the collection short hand for partial rendering. My question: How do I correctly fill out the the following view spec?
describe 'my_view' do
before(:each) do
assigns[:models] = Array.new(10, stub(Model))
end
it "should render the 'listing' part...
Does anyone know how to make rspec follow a redirect (in a controller spec)? (e.g test/unit has follow_redirect!)
I have tried "follow_redirect!" and "follow_redirect" but only get
undefined method `follow_redirect!' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1:0xb6df5294>
For example:
When I create an account the p...
I'm writing a sinatra app and testing it with rspec and rack/test (as described on sinatrarb.com).
It's been great so far, until I moved some rather procedural code from my domain objects to
sinatra helpers.
Since then, I've been trying to figure out how to test these in isolation ?
...
I am using rails 2.3.5 .rake spec works fine.
This is from spec --help.
spec --help
-f, --format FORMAT[:WHERE] Specifies what format to use for output. Specify WHERE to tell
the formatter where to write the output. All built-in formats
expect WHERE to be a ...
Here's some simple code that, for each argument specified, will add specific get/set methods named after that argument. If you write attr_option :foo, :bar, then you will see #foo/foo= and #bar/bar= instance methods on Config:
module Configurator
class Config
def initialize()
@options = {}
end
def self.attr_option(*...
Hi,
I'm developing a Rails application with Rspec for unit testing.
Weeks ago, Rspec used to migrate the database to the last version automatically when executing 'rake spec', but now it doesn't do it automatically, I have to implement everything for myself.
This happens in test environment, because my development data doesn't desap...
I'm currently testing my Rails controllers using RSpec. In one controller, I have a model that uses transactions, so that it will not be saved unless another nested model (whose data is filled in using fields_for) is also saved correctly.
The tests hit a snag when they reach the transaction. Some debugging output proves that the model...
Rake allows for the following syntax:
task :my_task, :arg1, :arg2 do |t, args|
puts "Args were: #{args}"
end
I'd like to be able to do the same, but with RSpecs SpecTask.
The following unfortunately fails:
desc "Run example with argument"
SpecTask.new('my_task'), :datafile do |t, args|
t.spec_files = FileList['*_spec.rb -datafil...
For my RSpec tests I would to automatically associate data files with each test. To clarify, if my tests each require an xml file as input data and then some xpath statements to validate the responses they get back I would like to externalize the xml and xpath as files and have the testing framework easily associate them with the particu...
If I have an example such as the following:
describe "A flux capacitor" do
it "should flux a lot" do
# how can I access the string object "A flux capacitor" in here???
...
end
end
How can I access the described string object "A flux capacitor"?
I've tried a few permutations of 'described_type' and 'described_class'
Such as:
s...
Guys,
Here my issuse:
I've got two models:
class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :username
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to :user
end
with this simple routes.rb file
TestProj::Application.routes.draw do |map|
res...
Given a Rakefile that executes some RSpec tests by way of a Spec::Rake::SpecTask, how can I programmatically determine the number of tests that passed, failed, and are pending once the task that ran the tests is finished?
...
Hi,
i have some action in my rails application
def show
@issue = Issue.find(params[:id], :include => [:answers, :comments])
@answers = @issue.answers
@comments = @issue.comments
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @issue }
end
end
and rspec test
def mo...
I want to automatically kick off a build whenever a file changes.
I've used autospec (RSpec) in Ruby and loved that.
How can this be done in bash?
...
Hello,
I want to get autotest to run Steak acceptance tests whenever one of my rails app's relevant files is changed. After studying Rspec's and Cucumber's own autotest configs, I'm trying the following mappings:
Autotest.add_hook :initialize do |at|
at.add_mapping(%r%^spec/acceptance/.*_spec.rb$%, true) { |filename, _|
filename...
A while ago I asked "How to test obtaining a list of files within a directory using RSpec?" and although I got a couple of useful answers, I'm still stuck, hence a new question with some more detail about what I'm trying to do.
I'm writing my first RubyGem. It has a module that contains a class method that returns an array containing a ...
I'm in Chapter 10 of the Foundation Rails 2 book. We're working with RSpec.
We're testing the 'index' action of the 'PluginsController'.
Here's the code for the controller:
class PluginsController < ApplicationController
# GET /plugins
# GET /plugins.xml
def index
@plugins = Plugin.find(:all)
...
I often want to compare arrays and make sure that they contain the same elements, in any order. IS there a consise way to do this in RSpec?
Here are methods that aren't acceptable:
#to_set
For example:
array.to_set.should == another_array.to_set
This fails when the arrays contain duplicate items.
#sort
For example:
array.sort.sh...
I'm in the process of upgrading an app to Rails 3/Rspec 2. I see that
stubbing a view helper method has changed in Rspec 2. It looks like
instead of doing template.stub!, we're now supposed to do view.stub!,
but I can't seem to get this to work on beta 10. I get an "undefined
local variable or method `view' for # < RSpec::Core::Exampl...
I'm trying to load up console to interact with some of my rspec mocking helpers. I expected that running script/console test would load an env similar to when I run spec. However, this doesn't appear to be the case. It looks like spec_helper is never loaded. Or, if it is, it's not actually running through the logic because spork has poll...