When I run spec from the command prompt on my rails app.
$ spec spec
I get the following error:
/Library/Ruby/Site/1.8/rubygems.rb:335:in `bin_path': can't find executable spec for rspec-2.0.0.beta.22 (Gem::Exception)
from /usr/bin/spec:19
However when I run
$ rake spec
The tests run fine.
What's the issue?
...
I am trying to write a spec were the number of examples i.e. 'it "should ..." do' are determined at runtime. I tried putting the 'it' method in my own method so that I could call it multiple times:
def new_method(test)
it "#{test} should... " do
end
end
However, the 'it' method is not available from the current Spec::E...
I am making a concerted effort to wrap my head around Rspec in order to move towards more of a TDD/BDD development pattern. However, I'm a long way off and struggling with some of the fundamentals:
Like, when exactly should I be using mocks/stubs and when shouldn't I?
Take for example this scenario: I have a Site model that has_many :b...
When I try and define (but not implement an it test) (pending method) using RSpec
describe "test" do
it "should not fail, but does"
end
I get this error when I try and run
ArgumentError in 'should not fail, but does'
wrong number of arguments (1 for 0)
Does anyone know why this is happening? Am I doing something wrong? (I am us...
I have just installed the RSpec 2.0 beta and I would like to use it with Textmate. I have tried setting my TM_RSPEC_HOME to /Users/zach/.rvm/gems/ruby-1.9.2-p0/bin/rspec (which is where the RSpec executable is), but I keep getting this error:
Can somebody please help me get RSpec correctly working with Textmate? Thanks.
...
Here's my code I'm spec'ing:
def vote_up
get_vote
@vote.value += 1 unless @vote.value == 1
@vote.save
respond_to do |format|
format.js { render :action => "vote", :layout => false }
end
end
Seems pretty straightforward. This is what I'm trying to spec it with :
it "should vote up" do
@mock_cat = Factory.create(:ca...
Hi there,
I'm basing my question on this one: http://stackoverflow.com/questions/1583760/rspec-mocks-verify-expectations-in-it-should-methods and also on these guidelines: http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
So, if there should be only one expectation per "it" block, what if I'm mixing mocks expectations...
I have a bunch of rspec tests that are taking entirely too long to run. I am trying to figure out where the bottleneck is and the logical place to start is using the standard libraries profile library. Execution is happening with JRuby 1.5.2 in this particular case. Here is the output after embedding the profile library in my spec:
% ...
I'm trying to stub out a method on my current_user (using a modified restful_authentication auth solution) with rspec. I'm completely unsure of how I can access this method in my controller specs. current_user by itself doesn't work. Do I need to get the controller itself first? How do I do this?
Using rails 2.3.5, rspec 1.3.0 and r...
Could you tell me how to setup simplecov to test models with rspec and controller with cucumber only?
I don't like it that rspec and cucumber coverage are mixed together...
...
Hi there,
I've been trying to mock a rest-client nested resource to test my class. Here's the test:
require 'rest_client'
require File.join(File.dirname(__FILE__), "/../src/job_resource.rb")
describe JobResource, "#has_stagein" do
before :each do
response = mock(String).stub!(:code).and_return(200)
job_resource = mock(Rest...
I used the approach details in Railscast espisode #197 on how to add dynamic input fields, but I'm not sure how to write an RSpec test for it. Suggestions?
def link_to_add_fields(name, f, association, path, *args)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.semantic_fields_for(association, n...
A Rails/tool specific version of: How deep are your unit tests?
Right now, I currently write:
Cucumber features (integration tests) - these test against the HTML/JS that is returned by our app, but sometimes also tests other things, like calls to third-party services.
RSpec controller tests (functional tests), originally only if the c...
Hi
I'm using Rails3 with rspec and shoulda. I have the below spec
describe PagesController, "on GET to show while logged off" do
before(:each) do
@site = Factory.create(:site)
@site.domains << Factory.create(:domain)
@site.save!
@site.pages << Factory.create(:page)
@site.menus << Factory.create(:menu, {:site=>@si...
Could you tell me how to test regex-code correctly?
I test my user-login attribute with following code:
# user.rb
class User < ActiveRecord::Base
#...
validates_format_of :login, :with => /^[a-zA-z0-9_.]{3,18}$/
end
# user_spec.rb
describe User do
before(:each) do
@user = Factory.build(:user)
@user.save
end
subject...
I'm trying to get autotest back up and running after moving my project to rails 3. After upgrading to rspec 2.0.0.beta.22, I can't seem to run autotest. I get the following:
bundler: command not found: c:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.22/bin/rspec
even though the binary does in fact exist in that location.
...
Hi,
Here my http basic authentication in the application controller file (application_controller.rb)
...
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "username" && password == "password"
end
end
and the default test for the index action ...
I'm trying to get a Rails (version 2.3.5) app set up to run RSpec and Autotest.
I've got both rspec (1.2.9) and rspec-rails (1.2.9) vendored as plugins in the app. I then have ZenTest 4.4.0, Autotest (4.3.2) and Autotest Rails (4.1.0) gems installed.
Whenever I run the autotest command in the app, all I get is this:
loading autotest/r...
Hey all,
I have a seemingly simple error but I can't seem to figure out what to do to resolve it. I have tried uninstalling and reinstalling but that hasn't helped me out. I am new to the terminal and to ruby/ruby on rails, so forgive my potentially stupid question. Does anyone know how to resolve this issue?
This is the exact error me...
I have a bunch of recurring tests for some of my controller actions, all of which require authentication. As a result, you end up seeing a lot of code like the following:
describe "authentication requests" do
it "should return 401 for unauthenticated :show" do
get :show
...
end
it "should return 401 for unauth...