rspec

Problems with RSpec and Chronic

I'm trying to use Chronic inside my non-rails project. When I try to get the specs with 'spec' I get the following error: $ spec spec/parsers/parser_english_spec.rb /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- chronic (LoadError) from /Library/Ruby/Site/1.8/rubygems/custom_requ...

How compatible are rspec and heckle?

I'm currently using test/unit, and I'm considering using rspec. However, I've noticed that rspec currently doesn't support heckle in ruby 1.9.1, and doesn't support passing any parameters to heckle apart from the target module/class/method. Are there any other current problems with using heckle and rspec, or do they work well together a...

How do you spec out "read-only" behavior of a Model?

For example, let's say I have a Question model, that has the boolean fields answered and closed. How would I test the behavior that a Question should be read only when marked as answered using RSpec? This seems like it's the behavior of the model, but I'm not sure how to best test it. Should I be using a before filter for this behavio...

Testing a sweeper with RSpec in Rails

I want to make sure my sweeper is being called as appropriate so I tried adding something like this: it "should clear the cache" do @foo = Foo.new(@create_params) Foo.should_receive(:new).with(@create_params).and_return(@foo) FooSweeper.should_receive(:after_save).with(@foo) post :create, @create_params end But I just ...

Setting the HTTP_REFERER in a global before(:all) in Rspec

In order to avoid adding request.env["HTTP_REFERER"] = '/' to a before block on every controller_spec file I create, I have tried to add this to the global config (in spec_helper.rb) config.before(:each) {request.env["HTTP_REFERER"] = '/'} The problem is, I get the following error: You have a nil object when you didn't expect it! ...

RSpec and Open-URI how do I mock raise a SocketError/TimeoutError

I want to be able to spec out that when Open-Uri open() calls either timeout or raise an exception such as SocketError I am handling things as expected, however I'm having trouble with this. Here is my spec (for SocketError): @obj.should_receive(:open).with("some_url").and_raise(SocketError) And the part of my object where I'm using ...

How do I change the default "www.example.com" domain for testing in rails?

I have a rails application which acts differently depending on what domain it's accessed at (for example www.myapp.com will invoke differently to user.myapp.com). In production use this all works fine but my test code always sees a hostname of "www.example.com". Is there a clean way of having a test specify the hostname it's pretending ...

Ruby Object#id warnings and Active Record

We keep seeing warnings like the following when we run our specs: Object#id will be deprecated; use Object#object_id The code in question is accessing the id of an ActiveRecord model (which is an attribute on the table, obviously, rather than the object instance ID in the Ruby VM). Does anyone know how to turn these particular war...

Is it a bad practice to randomly-generate test data?

Since I've started using rspec, I've had a problem with the notion of fixtures. My primary concerns are this: I use testing to reveal surprising behavior. I'm not always clever enough to enumerate every possible edge case for the examples I'm testing. Using hard-coded fixtures seems limiting because it only tests my code with the ve...

RSpec Gem does not seem to install dependencies...

$> jruby -v jruby 1.1.4 (ruby 1.8.6 patchlevel 114) (2008-08-28 rev 7570) [x86-java] $> gem install rspec JRuby limited openss loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Succesfully installed rspec-1.1.12 1 gem installed Installing ri documentation for rspec-1.1.12... Installin...

RSpec should redirect_to problem

Hi, I'm writing a spec for my Rails controller, this is the action I'm testing: def create @course = Course.new(params[:course]) if @course.save then #flash[:notice] = 'Course Created' redirect_to courses_path else render :action => 'new', :status => 400 end end And this is the spec that validates it: describe "PO...

How do I run my Specs with the previous version of Rspec?

I have been following an RSpec tutorial on one of my machines, in the hope of learning more about BDD and TDD. My setup was with Rails 2.2.2 and Rspec 1.1.12 Tonight I decided to continue on my primary machine and moved my code from my portable to my desktop. Not having RSpec, i installed the gem . . . sudo gem install rspec sudo gem ...

Switching test::unit with rspec under rails

Kinda odd question here: when you go with rpsec instead of test::unit on rails, what do you do with the test dir? Keep it (for any compatibility issues maybe?) or remove it? ...

How to get stories to work with restful_authentication and cucumber?

After cloning the latest stable versions of rails (2.3.2), rspec (1.2.2), cucumber (0.2.0.4...came out 2009-03-24), rspec-rails (1.2.2), restful-authentication (fixed formatted_user_path and a few other problems), webrat, rubyist-aasm (and a few others) into a clean rails application, and following (what I believe are) all the ins...

How to start with Rspec?

I have been into rails for the last 3 months. Now I wish to start BDD or TDD. I want to start with RSpec. How do I start with it? ...

Is Test::Unit still relevant in rails?

I am learning Rails the age old way. By reading Agile Web Development with Rails (3rd Edition) as a starting point. I am currently in the chapter that teaches Testing. I am also aware of other BDD Testing framework such as RSPec. So I was wondering if frameworks such as RSpec, Cucumber, Shoulda replace the need for knowing/using Test::Un...

Testing controller with rspec, factorygirl and restful authentication

Hi there. I'm still new to rails and testing with rspec, so hopefully you can help me. I have a controller which requires login. I use the restful authentication function of rails. To create things in tests I'm using the factory framework factorygirl. Ok the problem is the following: I want to test a controller (authentication requ...

Is it legal to stub the #class method of a Mock object when using RSpec in a Ruby on Rails application?

I would like to stub the #class method of a mock object: describe Letter do before(:each) do @john = mock("John") @john.stub!(:id).and_return(5) @john.stub!(:class).and_return(Person) # is this ok? @john.stub!(:name).and_return("John F.") Person.stub!(:find).and_return(@john) end it.should "have a valid #to fi...

Testing a sessions decorator lib in ruby on rails with rspec

I have this code in lib/user_session.rb Its used by one of my controllers via include UserSession. How can I test it? I've added tests in spec/lib/user_session.rb but the code relies on the session which I'm not sure how to mock. module UserSession def viewed session[:viewed] ||= Array.new return session[:viewed] end ...

Integrate test process with Rspec and Cucumber in a plugin using Desert

Hello, I'm developing some rails plugins with desert, and I would like to use tests with RSpec and Cucumber in the development. RSpec is integrated by default in Desert plugins, but it gives me some bugs. Finally I have created a minimal application which use my plugin, and I try to test it like a normal application without plugin. But I...