Hi Not sure if this is a RSpec problem or Rails but I believe is more a RSpec situation. What happens is that when I run my RSpecs tests all the BD is recreated, including the "schema_migration" table, because of this I get a problem saying: You have 29 pending migrations: 20100628100855 CreateCustomers 20100628103228 CreateAccounts 20100628172155 CreateCfgEntities ... etc It seems rails notices that the schema_migration tables is empty and that are migration scripts to run. This shouldn''t be needed because Rails uses schema.rb to recreate the table, right? I''m using JRuby with JDBC connection by the way. Anyone know how to resolve this? -- Posted via http://www.ruby-forum.com/.
On Jul 26, 2010, at 5:12 pm, Bruno Cardoso wrote:> Not sure if this is a RSpec problem or Rails but I believe is more a > RSpec situation. > > What happens is that when I run my RSpecs tests all the BD is recreated, > > ... > > Anyone know how to resolve this?Hi Bruno Are you running `rake spec` as opposed to the spec command? The default Rails spec task depends on the "db:test:prepare" task, which bombs your DB. I fixed this in my project with a file "lib/tasks/rspec_fixes.rake": class Rake::Task def overwrite(&block) @actions.clear enhance(&block) end end Rake::Task[''db:test:prepare''].overwrite do # We don''t want to run migrations or load the schema!!! end HTH Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran
David Chelimsky
2010-Jul-26 17:09 UTC
[rspec-users] Problem running RSpec tests with Rails
On Jul 26, 2010, at 11:12 AM, Bruno Cardoso wrote:> Hi > > Not sure if this is a RSpec problem or Rails but I believe is more a > RSpec situation. > > What happens is that when I run my RSpecs tests all the BD is recreated, > including the "schema_migration" table, because of this I get a problem > saying: > > You have 29 pending migrations: > 20100628100855 CreateCustomers > 20100628103228 CreateAccounts > 20100628172155 CreateCfgEntities > ... > etc > > It seems rails notices that the schema_migration tables is empty and > that are migration scripts to run. This shouldn''t be needed because > Rails uses schema.rb to recreate the table, right?The test database, yes, but it won''t get that far if you have any pending migrations in the development database. If you run "rake spec --trace" you''ll see that it runs db:test:prepare, which runs db:abort_if_pending_migrations. HTH, David> > I''m using JRuby with JDBC connection by the way. > > Anyone know how to resolve this?
David Chelimsky
2010-Jul-26 17:13 UTC
[rspec-users] Problem running RSpec tests with Rails
On Jul 26, 2010, at 11:50 AM, Ashley Moran wrote:> > On Jul 26, 2010, at 5:12 pm, Bruno Cardoso wrote: > >> Not sure if this is a RSpec problem or Rails but I believe is more a >> RSpec situation. >> >> What happens is that when I run my RSpecs tests all the BD is recreated, >> >> ... >> >> Anyone know how to resolve this? > > Hi Bruno > > Are you running `rake spec` as opposed to the spec command? The default Rails spec task depends on the "db:test:prepare" task, which bombs your DB.The test DB, not the development DB, right? If it''s bombing your dev DB then please file a bug report and we can sort it out.> I fixed this in my project with a file "lib/tasks/rspec_fixes.rake": > > class Rake::Task > def overwrite(&block) > @actions.clear > enhance(&block) > end > end > > Rake::Task[''db:test:prepare''].overwrite doAnother approach would be: Rake::Task[''spec''].prerequisites.clear Cheers, David> # We don''t want to run migrations or load the schema!!! > end > > HTH > > Ash > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashleymoran > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Thanks for the answers. What both solutions (from Ashley and David) do is not modify the BD in anyway, so nothing gets dropped and nothing is created. This resolves the problem but what if I want a clean installation in each test run? Is there a way to keep my "schema_migrations" table or remove the check for migration scripts? I would still like to recreate the rest of the tables. -- Posted via http://www.ruby-forum.com/.
Bruno Cardoso wrote:> Thanks for the answers. > > What both solutions (from Ashley and David) do is not modify the BD in > anyway, so nothing gets dropped and nothing is created. This resolves > the problem but what if I want a clean installation in each test run? Is > there a way to keep my "schema_migrations" table or remove the check for > migration scripts? I would still like to recreate the rest of the > tables.By the way, I''m using: "rake spec --trace" and the result was: ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment ** Execute db:abort_if_pending_migrations You have 12 pending migrations: 20100628100855 CreateCustomers ... Run "rake db:migrate" to update your database then try again. -- Posted via http://www.ruby-forum.com/.
On 26 Jul 2010, at 6:36 PM, Bruno Cardoso wrote:> What both solutions (from Ashley and David) do is not modify the BD in > anyway, so nothing gets dropped and nothing is created. This resolves > the problem but what if I want a clean installation in each test run? Is > there a way to keep my "schema_migrations" table or remove the check for > migration scripts? I would still like to recreate the rest of the > tables.One way is to avoid rake entirely - you could run the specs with `spec spec` or even just use autotest[1]. If you want to just empty the data from the tables you need database_cleaner[2]. If you want the database rebuilt as necessary when migrations change, you could use my database_resetter[3], plug plug :D Let me know if you''re trying to do something other than one of these. (It''s late, I have a habit of talking nonsense when I''m tired...) HTH Ash [1] eg http://ph7spot.com/musings/getting-started-with-autotest [2] http://github.com/bmabey/database_cleaner [3] http://rubygems.org/gems/database_resetter -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran
David Chelimsky
2010-Jul-27 02:32 UTC
[rspec-users] Problem running RSpec tests with Rails
On Jul 26, 2010, at 12:36 PM, Bruno Cardoso wrote:> Thanks for the answers. > > What both solutions (from Ashley and David) do is not modify the BD in > anyway, so nothing gets dropped and nothing is created. This resolves > the problem but what if I want a clean installation in each test run?So is your goal here to have the rake task(s) ignore the fact that you have pending migrations, but still have it reset the test database so it''s schema looks like the development database schema?> Is > there a way to keep my "schema_migrations" table or remove the check for > migration scripts? I would still like to recreate the rest of the > tables. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky wrote:> On Jul 26, 2010, at 12:36 PM, Bruno Cardoso wrote: > >> Thanks for the answers. >> >> What both solutions (from Ashley and David) do is not modify the BD in >> anyway, so nothing gets dropped and nothing is created. This resolves >> the problem but what if I want a clean installation in each test run? > > So is your goal here to have the rake task(s) ignore the fact that you > have pending migrations, but still have it reset the test database so > it''s schema looks like the development database schema?Exactly. I''m ok with the previous solution, it''s something we can do but I would like to know what I could do if I wanted to go by my first plan. -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Jul-27 10:37 UTC
[rspec-users] Problem running RSpec tests with Rails
On Jul 27, 2010, at 4:10 AM, Bruno Cardoso wrote:> David Chelimsky wrote: >> On Jul 26, 2010, at 12:36 PM, Bruno Cardoso wrote: >> >>> Thanks for the answers. >>> >>> What both solutions (from Ashley and David) do is not modify the BD in >>> anyway, so nothing gets dropped and nothing is created. This resolves >>> the problem but what if I want a clean installation in each test run? >> >> So is your goal here to have the rake task(s) ignore the fact that you >> have pending migrations, but still have it reset the test database so >> it''s schema looks like the development database schema? > > Exactly.OK. This is not Rails'' intent (which is why ''db:abort_if_pending_migrations'' is a prereq of ''db:test:prepare''), but you can use the same technique I described earlier on ''db:test:prepare'' instead of ''spec'': Rake::Task[''db:test:prepare''].clear_prerequisites Now you should get what you''re looking for. Cheers, David> > I''m ok with the previous solution, it''s something we can do but I would > like to know what I could do if I wanted to go by my first plan. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky wrote:> On Jul 27, 2010, at 4:10 AM, Bruno Cardoso wrote: > >>> have pending migrations, but still have it reset the test database so >>> it''s schema looks like the development database schema? >> >> Exactly. > > OK. This is not Rails'' intent (which is why > ''db:abort_if_pending_migrations'' is a prereq of ''db:test:prepare''), but > you can use the same technique I described earlier on ''db:test:prepare'' > instead of ''spec'': > > Rake::Task[''db:test:prepare''].clear_prerequisites > > Now you should get what you''re looking for. > > Cheers, > DavidYeah, it worked exactly like you said. Now I can choose between the two approaches. Thanks. -- Posted via http://www.ruby-forum.com/.