rspec

output_buffer is null on helper spec

I am trying to test the html block method inside the rails helper: def dashboard_widget(header, &proc) concat('<div class="dashboard-widget">') etc end The code works perfectly in the development environment, but the following test is failed: it "should be created" do helper.dashboard_widget('My widget') do "hello world" ...

AutoTest and Rspec testing with Rails

I just started using AutoTest. As far as i can tell i have everything configured, but everytime i run autotest then i get the following error coming from my test_helper.rb: richards-macbook-pro: $ autotest loading autotest/rails /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit...

How can I validate exits and aborts in RSpec?

I am trying to spec behaviors for command line arguments my script receives to ensure that all validation passes. Some of my command line arguments will result in abort or exit being invoked because the parameters supplied are missing or incorrect. I am trying something like this which isn't working: # something_spec.rb require 'somet...

Ruby: Send logger messages to a string variable?

I have a small framework that is logging some info and debug messages using the Logger object built into ruby. At run time, this works great. At unit test time (using rspec if it matters...) i would like to dump the logged messages to an in memory string variable. What's the easiest way to go about doing this? I was considering a monkey...

How should I spec this

The following spec works but I know it shouldn't be like this. I am having a hard time getting my head around rspec, in particular mocks and stubs. This is the model code class RecipeFermentable < ActiveRecord::Base belongs_to :recipe belongs_to :product def set_attributes() attrs = product.product_attributes self.ppg ...

How to have autotest and RSpec nicely formatted when comparing long texts (with \t and \n)?

I have a test in RSpec which compares to long text strings. When the test fails, I get a message like this: 'jobs partial should render the correct format for jobs' FAILED expected: "Job {\n\tName = \"name1-etc\"\n\tType = Backup\n\tMessages = Daemon\n\tPool = Default \n\tSchedule = \"schedule1\"\n\tStorage = storage1\n\tClient = \"name...

Rspec error on Cent OS 4.8 and rails 2.3.4

When I use "spec xxx.rb" to test certain ruby code, I got this error: Missing these required gems: webrat ~> 0.4.4 You're running: ruby 1.8.7.174 at /usr/local/bin/ruby rubygems 1.3.5 at /root/.gem/ruby/1.8, /usr/local/lib/ruby/gems/1.8 Run `rake gems:install` to install the missing gems. And I have webrat 0.5.3 gem running a...

How to get current context name of rspec?

if i have rspec like this describe 'Foo' do // init go here describe 'Sub-Foo' do it "should Bar" do // test go here // puts ... <-- need "Foo.Sub-Foo should Bar" here end end end How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here? It is similar to format with spe...

uninitialized constant Test::Unit::TestResult::TestResultFailureSupport

I get the error in subj when I'm trying to run specs or generators in a fresh rails project. This happens when I add shoulda to the mix. I added the following in the config/environment.rb: config.gem 'rspec', :version => '1.2.6', :lib => false config.gem 'rspec-rails', :version => '1.2.6', :lib => false config.gem "thoughtbot-shoulda"...

Rails RSpec with Multiple Databases

I run a Rails app, and we're in the process of splitting out our signup process to a separate app. The signup app has its own separate database (for CMS and collecting prospects), but it also needs to have access to the main database. This works really well using ActiveRecord::Base.establish_connection. However, I'd like to be able to ...

Testing modules in rspec

What are the best practices on testing modules in rspec? I have some modules that get included in few models and for now I simply have duplicate tests for each model (with few differences). Is there a way to DRY it up? ...

check for (the absence of) `puts` in RSpec

I am using rspec for my test in a ruby project, and I want to spec that my program should not output anything when the -q option is used. I tried: Kernel.should_not_receive :puts That did not result in a failed test when there was output to the console. How do I verify the absents of text output? ...

What test framework should I use to test my Rails model?

With the many testing framework that is available in the Ruby community namely: unittest, rspec, shoulda, and coulda, what would be the most appropriate testing framework to test my Rails model? Do they basically have the same functionality, which is to unittest my model? When should I use which? What is the advantage of using one and ...

Rspec Mocks: mock / yield the block from a method call

I've got this code: Net::SSH.start(@server, @username, :password => @password) do |ssh| output = ssh.exec!(@command) @logger.info 'SSH output: ' @logger.info output end I can mock the SSH.Start using RSpec's mock framework like this, to tell me that I've started the SSH session: Net::SSH.should_receive(:start)....

rspec mocks: verify expectations in it "should" methods?

I'm trying to use rspec's mocking to setup expectations that I can verify in the it "should" methods... but I don't know how to do this... when i call the .should_receive methods on the mock, it verifies the expected call as soon as the before :all method exits. here's a small example: describe Foo, "when doing something" do before :a...

Autospec / rspec not working, doing something wrong?

I wonder if this has its place on StackOverflow, but since it IS programming-related, I will shoot it away. Here's my problem. I am new to TDD and I love Ruby, so the obvious path I'm taking is testing stuff with rspec. Why obvious? I saw it in diverse screencasts and thought it was really neat. Then I saw "autospec" somewhere, and trie...

BDD on Rails - Is the community more behind Shoulda or RSpec?

For a new application I want to start dabbling in BDD and I'm trying to decide between using RSpec or Thoughtbot's Shoulda. I like the macros that Shoulda uses, and the fact that it doesn't seem to reinvent the way Ruby/Rails does testing, but simply provides an add-on. On the other hand, the macros seem like a bit too much "magic" ins...

testing threaded code in ruby

I'm writing a delayed_job clone for DataMapper. I've got what I think is working and tested code except for the thread in the worker process. I looked to delayed_job for how to test this but there are now tests for that portion of the code. Below is the code I need to test. ideas? (I'm using rspec BTW) def start say "*** Starting...

Trying to mock "new" through an association

This is in my controller @business = @current_user.businesses.new(params[:business]) @businesses is an array of business objects and I'm unsure of how to mock this cascade of calls. ...

No route matches error with application_controller spec

I have an application_controller spec that is failing since I removed the controller/action route from routes.rb. I get the following error: No route matches {:controller=>"application", :action=>"index"} I had many tests fail in the same way, but was able to fix them by including the correct parameters in the get call. So for insta...