notahat / machinist

Fixtures aren't fun. Machinist is.
MIT License
1.12k stars 134 forks source link

Making Machinist run on jruby, too #117

Closed ifesdjeen closed 9 years ago

ifesdjeen commented 12 years ago

Hi, here's a rather small pull request that adds jruby support.

Tests are passing :) on both platforms

jruby-1.6.5 :010 > RUBY_PLATFORM
 => "java"
➜  machinist git:(master) ✗ bundle install
Using rake (0.9.2) 
Using activesupport (3.0.9) 
Using builder (2.1.2) 
Using i18n (0.5.0) 
Using activemodel (3.0.9) 
Using arel (2.0.10) 
Using tzinfo (0.3.28) 
Using activerecord (3.0.9) 
Using activerecord-jdbc-adapter (1.2.2) 
Using jdbc-mysql (5.1.13) 
Using activerecord-jdbcmysql-adapter (1.2.2) 
Using diff-lcs (1.1.2) 
Using machinist (2.0) from source at . 
Using rcov (0.9.9) 
Using rdoc (3.6.1) 
Using rspec-core (2.6.4) 
Using rspec-expectations (2.6.0) 
Using rspec-mocks (2.6.0) 
Using rspec (2.6.0) 
Using bundler (1.2.0.pre.1) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
➜  machinist git:(master) ✗ bundle exec rspec spec     
-- create_table(:users, {:force=>true})
   -> 0.6490s
   -> 0 rows
-- create_table(:posts, {:force=>true})
   -> 0.0180s
   -> 0 rows
-- create_table(:comments, {:force=>true})
   -> 0.0190s
   -> 0 rows
-- create_table(:tags, {:force=>true})
   -> 0.0170s
   -> 0 rows
-- create_table(:posts_tags, {:id=>false, :force=>true})
   -> 0.0180s
   -> 0 rows
-- initialize_schema_migrations_table()
   -> 0.0020s
-- assume_migrated_upto_version(0, "db/migrate")
   -> 0.0020s
..............................

Finished in 0.656 seconds
30 examples, 0 failures

If you don't mind/want to, I could add .travis.yml with all supported rubies. What do you think?

vanyak commented 12 years ago

There is a bug in JRuby 1.6 which makes Machinist2 fail occasionally. https://jira.codehaus.org/browse/JRUBY-6035 This bug has been fixed in 1.7 only

attilagyorffy commented 11 years ago

I'm very sorry but I don't think this is a good way to handle this. The .gemspec is read at the time you build and release your gem, so any conditional logic in that file will be evaluated once when the gem is built and released on your machine.

What you need instead is to evaluate the platform at runtime. You can do this in your Gemfile instead as none of the ActiveRecord adapters is an actual dependency of Machinist:

platforms :ruby do
  gem "sqlite3"
end

platforms :jruby do
  gem "activerecord-jdbcsqlite3-adapter"
end

I've got a fork of Machinist that does exactly this: https://github.com/liquid/machinist/blob/master/Gemfile