0

I am using Ruby on Rails 3.0.9 and RSpec 2. In my spec file I have code like the following:

describe User do
  let(:authorizations) { Authorization.all.map(&:name) }

   it "should have a 'registered' value" do
     authorizations.should include("registered")
   end
end

When I run the above test I get:

User should have a 'registered' value
Failure/Error: authorizations.should include("registered")
expected [] to include "registered"
  Diff:
  @@ -1,2 +1,2 @@
  -registered
  +[]

Is it possible to solve the above error\problem? If so, how can I do?

Backo
  • 18,291
  • 27
  • 103
  • 170
  • first, you should populate your test db – apneadiving Sep 17 '11 at 20:04
  • @apneadiving - How can I populate the test database with no "hacking" (http://stackoverflow.com/questions/1574797/how-to-load-dbseed-data-into-test-database-automatically?answertab=votes#tab-top)? – Backo Sep 17 '11 at 20:18

1 Answers1

1

The above tells me that you have you all empty tables in your test database. You should either consider seeding your dev/test databases. (in case your consider Authorization to be a look up kind of entity)

or

using something a factory girl to create some test data for yourself in the before block of your spec.

jake
  • 2,371
  • 1
  • 20
  • 31
  • In the blog article related to seeding that you posted there is this phrase (at the end): "But, don’t go overboard and use seeds.rb for test or staging datasets – it should only be used for the base data that is necessary for your app to run". So, should I seed data in the test database? – Backo Sep 17 '11 at 20:34
  • Like i have said, if you consider the Authorization table to only every contain lookup data which you expect to be pre-populated when you application goes to production , then yes. Seed your dev database and test too. When I say lookup I mean, a table which will have a small set of values which will never be created by the application and is expected to be present when your application boots up. To me authorization sounds like one to me, but it depends on your domain. – jake Sep 17 '11 at 20:47
  • Look at [this](http://asciicasts.com/episodes/179-seed-data) and read up more about what "lookup" data means and whats should be seeded vs when fixutures or factory girl should be used. – jake Sep 17 '11 at 20:47