Mac OS 10.4
rspec (1.1.11, 1.1.4, 1.1.3, 0.5.15)
rspec-rails (1.1.11)
rspec_generator (0.5.15)
rails 2.2.2
ruby 1.8.6 (2007-03-13 patchlevel 0) [universal-darwin8.0]
Created a new project...
$ rails myproject
Installed rspec into the project...
$ script/generate rspec
Generated a resource...
$ script/generate rspec_scaffold myresource name:string description:text
Tried to run specs...
$ rake spec
Got this error:
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- ./spec/models/../../vendor/generators/rspec/lib/rspec_on_rails (MissingSourceFile)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
from ./spec/models/../spec_helper.rb:3
from ./spec/models/entry_spec.rb:1:in `require'
from ./spec/models/entry_spec.rb:1
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- /Users/ethan/project/project/spec/../vendor/generators/rspec/lib/rspec_on_rails (MissingSourceFile)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
from /Users/ethan/project/project/spec/spec_helper.rb:3
from ./spec/controllers/entries_controller_spec.rb:1:in `require'
from ./spec/controllers/entries_controller_spec.rb:1
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
Indeed, there is no such file...
vendor/generators, ls:
rspec_controller rspec_model
For rails3
To get the list
$ rails generate
To generate spec_helper.rb
$ rails g rspec:install
It seems to work for me.
I have installed rspec-rails, runned the rspec generator and when I give
$ script/generate
I get the list of generators:
Installed Generators
Rubygems: rspec, rspec_controller, rspec_model, rspec_scaffold
Builtin: controller, integration_test, mailer, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
After generating the scaffold with rspec_scaffold the specs pass.
Are the vendor/generators in your rails project ? I think you should delete them and use the generators from the gems instead.
Related
I currently have started learning Ruby On Rails. I have Ruby 2.3.1 and Rails 5.1.1 on my Debian Linux. I was following the instructions here : http://railscasts.com/episodes/417-foundation?view=asciicast
However, when I try to use the method rails g scaffold product name price:decimal --skip-stylesheets. I get this error;
"/usr/lib/ruby/vendor_ruby/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x000000016b9058> (NoMethodError)
from /root/Desktop/RubyOnRails/store/config/application.rb:12:in `<class:Application>'
from /root/Desktop/RubyOnRails/store/config/application.rb:10:in `<module:Store>'
from /root/Desktop/RubyOnRails/store/config/application.rb:9:in `<top (required)>'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:82:in `require'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:82:in `preload'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:143:in `serve'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:131:in `block in run'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `loop'
from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `run'
from /usr/lib/ruby/vendor_ruby/spring/application/boot.rb:18:in `<top (required)>'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'"
I get the error, also when I try to generate a controller or model. Because of this error, I can not follow any tutorial. I have tried to reinstall Rails but did not work.How can I solve this? Thank you in advanced.
Use
rails g scaffold product name price:decimal --no-stylesheets
instead --skip
You can do also in config/application.rb something like this.
config.generators do |g|
g.stylesheets false
end
You can see more details here http://guides.rubyonrails.org/configuring.html#configuring-generators
Try following steps:
1. rails new demo
2. cd demo
3. rake db:create
4. rails g scaffold product name:string price:float
5. rake db:migrate
6. rails server
I solved it by reinstalling Ruby and Rails again
Add this line to config/application.rb:
require 'neo4j/railtie'
I am following the Kevin Skoglund tutorial for Ruby on Rails called Ruby on Rails 4 Essential Training. In the section 'Create Record' I am having the following error after simply trying to create a record:
George$ pwd
/Users/George/Sites/simple_cms
George$ rails console
Loading development environment (Rails 4.2.0)
irb(main):001:0> subject = Subject.new
NameError: uninitialized constant Subject
from (irb):1
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/George/Sites/simple_cms/bin/rails:8:in `<top (required)>'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
irb(main):002:0>
As I am still in the early stages of learning I cannot establish what the cause might be although it appears to be gem related based on the errors return.
If anyone has any suggestion and maybe a tip on how I can work out what the error and fix is for myself it would be appreciated as I really want to keep learning.
George$ pwd
/Users/George/Sites/simple_cms
George$ rails console
Loading development environment (Rails 4.2.0)
> rails generate model Subject name:string type:string
> rake db:migrate
> rails console
> sub = Subject.new
Try this.
When loading the Rails console in sandbox as following the tutorial, i can't create a new user object ? I've got this message :
>> User.new
NameError: uninitialized constant User
from (irb):1
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/Genosia/code/sample_app/bin/rails:8:in `<top (required)>'
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/Genosia/.rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
You must have a user class in your app/models folder.
You can use the rails generator for that:
bundle exec rails g model user name:string date_of_birth:date ...
That will create the model under app/models and the migration under db/migrate
To run the migrations run
bundle exec rake db:migrate
bundle exec rails c --sandbox
Then it should work.
Note that opening the console in sandbox mode will rollback all the database changes when you close it.
To have persistent changes run
bundle exec rails c
I'm trying to create an xml runner to make a result report of Rails unit testing. Here is a code I have:
require 'test/unit'
require 'test/unit/ui/console/testrunner'
class FastFailRunner < Test::Unit::UI::Console::TestRunner
def add_fault(fault)
#faults << fault
nl
output("%3d) %s" % [#faults.length, fault.long_display])
output("--")
#already_outputted = true
end
def finished(elapsed_time)
nl
output("Finished in #{elapsed_time} seconds.")
nl
output(#result)
end
end
Test::Unit::AutoRunner::RUNNERS[:fastfail] = proc do |r|
FastFailRunner
end
When I run it as TESTOPTS="/home/alex/RubymineProjects/app2/test/unit/runner.rb --runner=xml" rake test
... I get an error (pretty weird error)
/home/alex/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
gem install minitest
/home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
I tried to require test/unit/ui/xml/testrunner.rb but no luck.
Any thoughts?
If you are in Ruby 1.8.7 you can say:
require 'test/unit/ui/console/testrunner'
p Test::Unit::UI::Console::TestRunner # => no problem
(There is no such file as test/unit/ui/xml/testrunner.rb so I'm not sure what you were up to there.)
Look in the docs in test/unit.rb, there's actually sample code showing you how to do this require: http://www.ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/Test/Unit.html.
However, the problem is that you are in Ruby 1.9.3. There is no /test/unit in Ruby 1.9.3! Well, there is, but it's just a compatibility layer for basic tests; there is certainly no test/unit/ui/console/testrunner, and no module/class Test::Unit::UI::Console::TestRunner.
Instead, there's minitest. You can read the docs on minitest to see how to make a test runner. http://docs.seattlerb.org/minitest/
One thing to consider is that Test::Unit was included in the default Ruby 1.8.7 installation. If you want to use it in with a later version of Ruby then go ahead and install it as a gem.
sudo gem install test-unit
http://test-unit.rubyforge.org/
I'm trying to add activeadmin to my rails 3.0.3 app.
I'm following the instructions here
When I run - rake db:migrate I get the following error -
rake aborted!
uninitialized constant Formtastic::SemanticFormHelper
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `eval'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/resource_controller.rb:1:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:3:in `<module:Dashboards>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:2:in `<module:ActiveAdmin>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:1:in `<top (required)>'
(eval):1:in `generate_dashboard_controller'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `eval'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `generate_dashboard_controller'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:38:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:147:in `new'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:147:in `find_or_create_namespace'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:282:in `load_default_namespace'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:188:in `load!'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:212:in `routes'
You seem to be missing the formtastic gem. In the current version of active-admin (0.3.2) it is correctly specified as a dependency.
So I hope updating the activeadmin gem (bundle update activeadmin) will fix it.
If that does not fix it, I would add formtastic explicitly to the Gemfile.
Hope this helps.
In rails 3 the Formtastic::SemanticFormHelper became => Formtastic::Helpers::FormHelper
Don't forget to load your lib. By default rails don't load them so you can just uncomment config.autoload_paths += %W(#{config.root}/lib) in your application.rb