Hi, I have been attempting to get rspec running on Ubuntu without much luck. I finally got it to go, but I can''t figure out how to turn off the database access. I created a new test project named myspec Ran script/generate rspec and then so I would have restful routes, ran script/generate rspec_scaffold page title:string body:text Out of the box, 5 of the tests are failing because the test database is not being populated. This is probably a config issue, but after many hours, I can''t figure what to do. Thanks in advance ActiveRecord::StatementInvalid in ''Page should create a new instance given valid attributes'' Mysql::Error: Table ''myspec_test.pages'' doesn''t exist: SHOW FIELDS FROM `pages` ./spec/models/page_spec.rb:12: spec/views/pages/show.html.erb_spec.rb:3: ./spec/models/page_spec.rb:12: require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') describe Page do before(:each) do @valid_attributes = { :title => "value for title", :body => "value for body" } end it "should create a new instance given valid attributes" do Page.create!(@valid_attributes) #this is line 12 end end spec/views/pages/show.html.erb_spec.rb:3: require File.expand_path(File.dirname(__FILE__) + ''/../../ spec_helper'') describe "/pages/show.html.erb" do include PagesHelper #line 3 before(:each) do assigns[:page] = @page = stub_model(Page, :title => "value for title", :body => "value for body" ) end it "should render attributes in <p>" do render "/pages/show.html.erb" response.should have_text(/value\ for\ title/) response.should have_text(/value\ for\ body/) end end
David Salgado
2008-Jul-21 07:27 UTC
[rspec-users] Newbie question, populate or ignore test db
Have you created the database "myspec_test"? If not, try running "rake db:create:all". If you have created it, then perhaps the test db doesn''t have the right tables. So, try "rake db:test:prepare". You''ll need to do that after every migration as well. HTH David 2008/7/21 Teedub <twscannell at gmail.com>:> Hi, > > I have been attempting to get rspec running on Ubuntu without much > luck. > I finally got it to go, but I can''t figure out how to turn off the > database access. > > I created a new test project named myspec > Ran > script/generate rspec > > and then so I would have restful routes, ran > script/generate rspec_scaffold page title:string body:text > > Out of the box, 5 of the tests are failing because the test database > is not being populated. This is probably a config issue, but after > many hours, I can''t figure what to do. > > Thanks in advance > > ActiveRecord::StatementInvalid in ''Page should create a new instance > given valid attributes'' > Mysql::Error: Table ''myspec_test.pages'' doesn''t exist: SHOW FIELDS > FROM `pages` > ./spec/models/page_spec.rb:12: > spec/views/pages/show.html.erb_spec.rb:3: > > > ./spec/models/page_spec.rb:12: > require File.expand_path(File.dirname(__FILE__) + ''/../spec_helper'') > > describe Page do > before(:each) do > @valid_attributes = { > :title => "value for title", > :body => "value for body" > } > end > > it "should create a new instance given valid attributes" do > Page.create!(@valid_attributes) #this is line 12 > end > end > > > spec/views/pages/show.html.erb_spec.rb:3: > require File.expand_path(File.dirname(__FILE__) + ''/../../ > spec_helper'') > > describe "/pages/show.html.erb" do > include PagesHelper #line 3 > > before(:each) do > assigns[:page] = @page = stub_model(Page, > :title => "value for title", > :body => "value for body" > ) > end > > it "should render attributes in <p>" do > render "/pages/show.html.erb" > response.should have_text(/value\ for\ title/) > response.should have_text(/value\ for\ body/) > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Rahoul Baruah
2008-Jul-21 08:01 UTC
[rspec-users] Newbie question, populate or ignore test db
On 21 Jul 2008, at 08:27, David Salgado wrote:> If you have created it, then perhaps the test db doesn''t have the > right tables. So, try "rake db:test:prepare". You''ll need to do that > after every migration as well.Once your test database is built, using "rake spec" should ensure that your test database matches the structure of your dev database, before running your specifications. Baz. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080721/5808d225/attachment-0001.html>
Thanks rake db:test:prepare did the trick. I am still a bit confused as to why rake cares about a database that it isn''t using. But I guess that will all fall into place in my brain one day. Teedub On Jul 21, 1:01?am, Rahoul Baruah <b... at madeofstone.net> wrote:> On 21 Jul 2008, at 08:27, David Salgado wrote: > > > If you have created it, then perhaps the test db doesn''t have the > > right tables. So, try "rake db:test:prepare". You''ll need to do that > > after every migration as well. > > Once your test database is built, using "rake spec" should ensure ? > that your test database matches the structure of your dev database, ? > before running your specifications. > > Baz. > > Rahoul Baruah > Web design and development:http://www.3hv.co.uk/ > Serious Rails Hosting:http://www.brightbox.co.uk/ > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Bart Zonneveld
2008-Jul-22 07:09 UTC
[rspec-users] Newbie question, populate or ignore test db
On 22-jul-2008, at 6:43, Teedub wrote:> Thanks > rake db:test:prepare did the trick. I am still a bit confused as to > why rake cares about a database that it isn''t using. > But I guess that will all fall into place in my brain one day.Well, the test database is for ehrm, testing :). So rake is actually using it. gr, bartz> On Jul 21, 1:01 am, Rahoul Baruah <b... at madeofstone.net> wrote: >> On 21 Jul 2008, at 08:27, David Salgado wrote: >> >>> If you have created it, then perhaps the test db doesn''t have the >>> right tables. So, try "rake db:test:prepare". You''ll need to do that >>> after every migration as well. >> >> Once your test database is built, using "rake spec" should ensure >> that your test database matches the structure of your dev database, >> before running your specifications. >> >> Baz. >> >> Rahoul Baruah >> Web design and development:http://www.3hv.co.uk/ >> Serious Rails Hosting:http://www.brightbox.co.uk/ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/ >> rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
For some reason I thought I was using the fixture that thescript/ generate rspec_scaffold method created for me. And further that the fixture didn''t use a database, but pretended that it did. Thanks On Jul 22, 12:09?am, Bart Zonneveld <l... at superinfinite.com> wrote:> On 22-jul-2008, at 6:43, Teedub wrote: > > > Thanks > > rake db:test:prepare did the trick. I am still a bit confused as to > > why rake cares about a database that it isn''t using. > > But I guess that will all fall into place in my brain one day. > > Well, the test database is for ehrm, testing :). So rake is actually ? > using it. > > gr, > bartz > > > > > On Jul 21, 1:01 am, Rahoul Baruah <b... at madeofstone.net> wrote: > >> On 21 Jul 2008, at 08:27, David Salgado wrote: > > >>> If you have created it, then perhaps the test db doesn''t have the > >>> right tables. So, try "rake db:test:prepare". You''ll need to do that > >>> after every migration as well. > > >> Once your test database is built, using "rake spec" should ensure > >> that your test database matches the structure of your dev database, > >> before running your specifications. > > >> Baz. > > >> Rahoul Baruah > >> Web design and development:http://www.3hv.co.uk/ > >> Serious Rails Hosting:http://www.brightbox.co.uk/ > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/ > >> rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users