rspec

Writing quality specifications with SpecFlow (or equivalent tool)

I've been playing with SpecFlow for the last couple of days. During that time I realized I should brush up on writing quality specs for these systems. Could someone point me towards some resources with best practices on creating quality specifications for SpecFlow or similar tools? ...

How do I test a Formtastic custom input with rspec?

I have a rubygem that defines a custom SemanticFormBuilder class which adds a new Formtastic input type. The code works as expected, but I cannot figure out how to add tests for it. I was thinking I could do something like load up Formtastic, call semantic_form_for, and then ad ann input that uses my custom :as type, but I have no idea w...

Mocks: Test for presence/absense of break/return in a block

I'm trying to write out some examples for a Proc that will be passed to a function as a block to be yield'd various values. I'd like to be able to specify that given some inputs, it will just return a value to the function given other values, it will break (or return) a value, skipping the rest of the function's execution. How can ...

How can I run Ruby specs and/or tests in MacVim without locking up MacVim?

About 6 months ago I switched from TextMate to MacVim for all of my development work, which primarily consists of coding in Ruby, Ruby on Rails and JavaScript. With TextMate, whenever I needed to run a spec or a test, I could just command+R on the test or spec file and another window would open and the results would be displayed with t...

RSpec, no such file to load when loading helpers

I have a Sinatra app that uses RSpec2 beta 19. My application.rb and app_helpers.rb are in a directory /lib. The application obviously loads the helper module and my application runs but when I run RSpec I get an error that it is unable to located any gems required in the helper module. I am now sure how to load the application.rb withou...

testing a has_one relationship?

I have an object class User < ActiveRecord::Base has_one :subscription end and I have this test: it "should increment shipped count when item_shipped" do @user.attributes = @valid_attributes @user.save subscription = mock_model(Subscription) subscription.stub!(:item_shipped!) subscription.stub!(:user_id) ...

RSpec-2 and Devise

Hi, i create a customized devise registration controller and i want to test it with rspec. I've tried it with a very simple test : it "creates a new parent" do Parent.should receive(:new) post :create end but i get this exception: Failures: 1) Parent::RegistrationsController POST create creates a new parent Failure/Error:...

Abnormal termination running an RSpec/Watir script

I am using Ruby 1.8.6, Watir 1.6.6, and RSpec 1.3.0. When I run the following script, it "terminates" (term given in EclipsePDT IDE) but no error is listed. Same when I run it from the c-prompt on windows, except no "terminate". The browser never opens. Anybody got a clue? It runs OK if I take off the describe, it, and end lines. descri...

How can I make Rack::Session::Pool work in a test using Sinatra and RSpec?

How can I make sessions work in my RSpec tests? I have tried something like this: describe "createnewlist_route_spec" do include Rack::Test::Methods use Rack::Session::Pool def app @app ||= Sinatra::Application end it "should save listitem to database" do post '/addnewlistitem', {:item => 'testitem'}, :sessions =>...

rspec-2.0 and rcov

The verify_rcov task is no longer available in new rspec-2.0. just curious on how you will tackle this issue. I certainly can do what rspec 1.x did - check the html file to get the number. Is there better way for this? ...

Using RSpec, how to verify from tags and link tags in view pages?

In view pages, people use form tag helpers and link helpers etc. If I then rename a controller, or a action, my view pages may break. How can I unit test view related tags for this kind of a breakage? ...

Using the expect{}.to change, isn't passing, but works in console

I'm trying to test a method on my model. Running in the console works, but my rspec test does not pass. Checkout the code: Model: def import(master) hsh = master.attributes.delete_if { |k,v| k == 'id' } self.update_attributes(hsh) end Rspec test: describe "#import" do let(:master) { Factory(:sheet, :work_order => 'M1234', :sa...

How to know if Spork is running

Hi. I'm trying to speed up "rspecing" in a rails 2.3.8 app with spork. When I run spork in the root of the project I get: (...stuff...) No server is running Running specs locally: Spork is ready and listening on 8989! And then, if I run specs, the message No server is running Running specs locally which appears if I run them w...

Rails 3 - How do I get Rspec spec/ & autotest to work?

I was all setup with Rspec and Autotest before I updated to Rails 3. When running rspec spec/ I'm getting: * spec/spec.opts is deprecated. * please use ./.rspec or ~/.rspec instead. I tried changed spec.opts to spec.rspec and running rspec spec/ again. But now I get a whole mess of warnings: DEPRECATION WARNING: Use toplevel init.rb...

rspec user story feature vs cucumber

Just to be up front, although the title appears to be similar to the thread http://stackoverflow.com/questions/393622/rspec-vs-cucumber-rspec-stories, however my question is fundamentally different. I understand the difference between testing user stories and testing behavior of objects individually. My question is, why is Cucumber usua...

Rspec, shoulda and spork does not work together

Hi all, when I run rspec spec/models result is OK. But when I use spork, every test where shoulda macros (like it { should validate_presence_of(:title) } is used FAILS with error like: undefined method 'validate_presence_of' for ... I use: rails (3.0.0) shoulda (2.11.3) spork (0.8.4) rspec-rails (>= 2.0.0.beta.22) spec/spec_helper....

Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs before(:all) do ActiveSupport::TestCase.use_transactional_fixtures = false end after(:all) do ActiveSup...

Rspec not displaying colours

I'm running Rspec 2.0.0rc on Windows 7. I am also running the win32console gem (1.3.0 x86-mingw32). The colours aren't being displayed - everything is showing up in boring old white/grey. What am I doing wrong? Edit: I also tried Rspec 2.0.0. and had the same problem ...

Behavior Driven Development using existing software components

I'm currently reading through the beta version of The Rspec Book: http://www.pragprog.com/titles/achbd/the-rspec-book It describes The Behaviour Driven Development Cycle (red, green, refactor) as taking small steps during the development process. This means adding features one at a time. My question is: If I were to describe a single...

Rails 3 - If I'm using RSpec, can I just delete the 'test' folder?

While trying to migrate, I keep getting this error: rake aborted! test-unit is not part of the bundle. Add it to Gemfile. If I'm using RSpec, can I just delete the test folder altogether? ...