Bootstrap Devise Cancan Rails - Rspec Failure - ruby-on-rails

I just installed Rails3 Bootstrap Device Cancan in my local machine and ran rake spec but I'm getting all test failures with below error in common:
undefined local variable or method 'postgresql_version' for #<ActiveRecord::ConnectionAdaptors::SQLite3Adaptor:0x489dff8>
I'm not sure why I'm getting this since I followed the instructions on https://github.com/RailsApps/rails3-bootstrap-devise-cancan carefully.
I'm currently running this on Windows 8 and used Bitnami RubyStack to run CMD

I ran into the same problem and this is how I resolved it.
It looks like there is a problem with version 1.1.0 of database_cleaner. See "database_cleaner >= 1.1.0 is broken for SQLite" (https://github.com/gregbell/active_admin/issues/2388). I updated my Gemfile to set
gem 'database_cleaner', '< 1.1.0'
then ran "bundle install" and after it completed, "rake spec" ran cleanly.

Double-check your database.yml. Refer to Configuring Rails Applications, Section 3.12, Configuring a Database.
Did you intend to use sqlite3? Is sqlite3 in your Gemfile? Naturally, SQLite3Adaptor will not respond to postgresql_version! Can you include a few more lines of the stack trace?
I doubt this has anything to do with devise or cancan.

Related

Gem 'better_errors' not working Rails 5.0.0

I installed gem better_errors version 2.1.1 for my ruby on rails application. However, I still get the same old debug page. I have also installed the gem binding_of_caller. I even installed the three gems which as shown as runtime dependencies for better_errors, namely erubis, coderay and rack(see the gem page here). All this to no avail.
I have also tried other solutions, one is this. All this to no avail.
I am using Ubuntu 16.04, rails 5.0.0.1 and ruby 2.3.1p112.
Make sure you are not testing with just a routing error / 404 exception, as that will no longer end up triggering better_errors.
Best way to confirm whether it's working or not would be to put some undefined variable in a controller action and then hitting that URL.
You installed the gem in development?
'group :development do
gem "better_errors"
end'
I just added better_errors to my Rails 5 app and its working fine.

rails plugin vs bundle gem

This two commands seem to generate practically the same thing
rails plugin new __name__
bundle gem __name__
There is a hidden detail I haven't notice?
which one do you use, and basically, why?
Thanks
They can all generate a barebone gem but they are different.
rails plugin new could generate a dummy app inside test, and a basic test_helper, which would be very handy if you want to add some functional/integration tests in gem. You can also revise that a bit to use Rspec. bundle gem would not do that.
If you develop the gem for Rails and need such tests, rails plugin would be better. Otherwise bundle or a gem generating gem jeweller.
Plugins are more or less deprecated in favor of gems in recent versions of Rails.
As far as I can tell, running rails plugin my_gem simply creates a 'my_gem' directory in the root of your rails app.
It's not too much different from running bundle gem my_gem except that it stubs out a couple of test files, and runs bundle install.
This may be useful if you're creating a gem that's made to be run on rails - where you need a "rails environment" (see the test/dummy/app directory).
Still, if you do it this way, it appears the gem is added right into the root of your rails project. You could always move it, but if you were to run bundle gem you could do so wherever you want.

How can I get Capybara #javascript tags executing correctly in Cucumber on a Rails 3 project?

I've swapped out Webrat for Capybara on a new Rails 3 project. I ran through Tim Riley's great post on it here ( http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ), and also cloned his repository, executed the example cucumber feature, and saw the browser window fire open. So the whole Cucumber, Capybara, Selenium stack seems to work fine in that instance.
However if I create a new Rails 3 project, run through setting up a similar example project, and annotate a Scenario with #javascript the browser window does not fire, and the Cucumber Scenario just fails with the usual Command failed with status (1) event (which, in the instance of failing or pending steps, Cucumber triggers by design for the benefit of CI tools).
Apart from the #javascript functionality provided by Capybara, all other features work fine.
Am I missing something incredibly obvious? Is there a way for a BDD newcomer to look deeper into the issues (the stack trace just shows the standard rake error when Cucumber fails).
rvm 1.9.2-head
gem 'rails', '3.0.0.rc'
gem 'cucumber'
gem 'cucumber-rails'
gem 'capybara'
gem 'culerity'
gem 'celerity', :require => nil
The issue is actually with cucumber-rails and a missing dependency on DatabaseCleaner: http://github.com/aslakhellesoy/cucumber-rails/issues#issue/36
The issue is manifested when adding a #javascript tag to a cucumber feature. By default the cucumber options suppress the warnings that would have alerted me to the fact. By updating config/cucumber.yml to:
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~#wip"
the error is shown when running cucumber: uninitialized constant DatabaseCleaner (NameError)
The quick fix in this case is to add gem 'database_cleaner' to the project's Gemfile.
Capybara is "lazy" in that it will open the browser window first when it is actually needed. If you're actually doing something that would require a browser, Capybara won't open one.
Maybe you have not installed the mongrel gem. The browser automation is somehow not working with webrick and i have experienced the same silent failing the you describe here.
Adding
gem 'mongrel', '>= 1.2.0.beta.1'
to my Gemfile solved it.
I made an example app on how to configure that: github.com/lailsonbm/contact_manager_app/

Couldn't find 'rspec' generator

I'm trying to install RSpec as a gem after having it installed as a plugin. I've gone ahead and followed the directions found here http://github.com/dchelimsky/rspec-rails/wikis for the section titled rspec and rspec-rails gems. When I run ruby script/generate rspec, I get the error Couldn't find 'rspec' generator. Do only the plugins work? If so, why do they even offer the gems for rspec and rspec-rails? I'm running a frozen copy of Rails 2.1.2, and the version of rpsec and rspec-rails I'm using is the newest for today (Nov 7, 2008) 1.1.11.
EDIT Nov 12, 2008
I have both the rspec and rspec-rails gems installed. I've unpacked the gems into the vender/gems folder. Both are version 1.1.11.
Since RSpec has been become the default testing framework in Rails you no longer need to create spec docs via the rspec generators:
Rails 2 RSpec generator
rails generate rspec_model mymodel
Rails 3 RSpec generator
With RSpec as the default testing framework simply use Rails' own generators. This will construct all of the files you need including the RSpec tests. e.g.
$rails generate model mymodel
invoke active_record
create db/migrate/20110531144454_create_mymodels.rb
create app/models/mymodel.rb
invoke rspec
create spec/models/mymodel_spec.rb
Have you installed both rspec and rspec-rails gems?
script/generate rspec
requires rspec-rails gem to be installed.
For Rails 3 and rspec 2+
You must make sure you include 'rspec' and rspec-rails' in your Gemfile
Run Bundle Install
then run rails g rspec:install
If you are using rails 2.3 You need to use
ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.3.3'
and then
ruby script/generate rspec
Is there supposed to be an 'rspec' generator? I've only used the following:
script/generate rspec_model mymodel
script/generate rspec_controller mycontroller
I've had this problem before, it boiled down to the version of RSpec I had not working with the version of Rails I was using. IIRC it was a 2.1 Rails and the updated RSpec hadn't been released as a gem. In fact, 1.1.11 is the gem I have, which would be the latest available (ignoring github gems), so I'm pretty sure that's exactly what my problem was.
I've taken to just using the head of master rspec with whatever version of Rails I happen to be on, it seems stable to me (and isn't going to break things in production, unless somehow a test broke with a false positive).
I do it with git using submodules, for example:
git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec_on_rails
In case anyone is wondering about Rails 3 now,
this seems to do the trick for me:
http://github.com/rspec/rspec-rails/blob/29817932b99fc45adaa93c3f75d503c69aafcaef/README.markdown
I'm using rails 2.3.9. I started of trying to use the gem(s) but just couldn't get the generator for rspec to show up. Then I installed the plugin(s) using the instructions on https://github.com/dchelimsky/rspec/wiki/rails and that did the trick.
On Fedora 9 (OLPC) I did:
$ sudo gem install rspec
$ sudo gem install rspec-rails
Those got me to where I could run
$ ruby script/generate rspec
This worked for me, whereas the git instructions did not work.
If you are using bundler version 1.0.8 you should $ gem update bundler to a newer version 1.0.9.
I had the same symptons and updating bundler helped me out.
Now $ rails g is using gems defined in the Gemfile. Also I grouped my gems like this:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :test, :development do
gem 'capybara', '0.4.1.1'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'rspec-rails', '~> 2.4'
gem 'launchy'
end
(Note that test gems are also in the :development group.)
Have a nice day :)
Lukas
If you type script/rails generate, the only RSpec generator you'll actually see is rspec:install. That's because RSpec is registered with Rails as the test framework, so whenever you generate application components like models, controllers, etc, RSpec specs are generated instead of Test::Unit tests.
Please note that the generators are there to help you get started, but they are no substitute for writing your own examples, and they are only guaranteed to work out of the box for the default scenario (ActiveRecord & Webrat).
https://github.com/rspec/rspec-rails
You might need to run bundle exec :
bundle exec rails g rspec:install
You'll need to do
sudo gem install cucumber-rails

What does error occurred while evaluating nil.dependencies mean?

I'm running ruby on rails v2.2.2 and when I run rake gems I get this error.
$ rake gems --trace
- [I] settingslogic
rake aborted!
You have a nil object when you didn't expect it!
The error occured while evaluating nil.dependencies
/vendor/rails/railities/lib/rails/gem_dependency.rb:77:in `dependencies'
I figured out what was going on. There is a bug in the core rake gems function where it assumed there were specifications for the gem and would error out when it didn't exist for that gem.
Here is the ticket for this issue with a working patch
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1464
Could be a problem with a gem it's trying to load, or your setup of required gems. Check config/environment.rb for any odd-looking config.gem lines, and do an update of all your gems (sudo gem update).
There is a bit more detail here with two alternate workarounds
-add one line to the dependency code in rails
or
-specify gem dependencies before the gem

Resources