Create a rails 3 plugin with RSpec - ruby-on-rails-3

The question explains itself...
I wanna test a new rails plugin with rspec, are there any specific generators, gems?
I used rails g plugin blabla and I got an error on rspec generator: error rspec [not found].

FYI - there is an open github issue about this: https://github.com/rspec/rspec-rails/issues/#issue/258.

Related

Chapter 5 - Ruby on Rails Tutorial - undefined method `has_title?' when running RSpec tests

Just trying to get through the last bit of chapter 5 in Michael Hartl's Ruby on Rails Tutorial and getting another error running RSpec tests.
The output is :
Static pages should have the right links on the layout
Failure/Error: expect(page).to have_title('About Us')
NoMethodError:
undefined method has_title?' for #<Capybara::Session>
# ./spec/requests/static_pages_spec.rb:59:inblock (2 levels) in '
and results from the line starting expect(page) in the following code in static_pages_spec.rb :
it "should have the right links on the layout" do
visit root_path
click_link "About"
expect(page).to have_title(full_title('About Us'))
end
Note : This happens running with or without Spork
Can anyone point me in the right direction please ?
Thanks,
Bazza
The have_title function is supported from Capybara 2.1. I suppose you have an older version of Capybara in your Gemfile. So, update your Gemfile with
gem 'capybara', '2.1.0'
then update Capybara like this
bundle update capybara
and rerun the specs using rspec. It should work now
Refer to this post for other options

acts_as_commentable_with_threading uninitialized constant Post::Comment Rails 3.1.3

I have upgraded my application from Rails 2.3.5 to Rails 3.1.3. I had acts_as_commentable_with_threading and awesome_nested_set as plugins. Now I have added in GemFile for Rails 3.1.3 as below
gem 'awesome_nested_set'
gem 'acts_as_commentable_with_threading'
I have code in the model as below
class Post < ActiveRecord::Base
acts_as_commentable
end
The migration for acts_as_commentable_with_threading is already applied in the database.
I have statement in the view as
<%= pluralize(post.root_comments.size, "comment") %> on this post
When I try to load that view I get error at that line as
uninitialized constant Post::Comment
What can be the problem. Please help me.
Thanks in advance!
You might have forgot to run the generator and the migration afterwards:
rails generate acts_as_commentable_with_threading_migration
or
rails generate acts_as_commentable_upgrade_migration
and after:
bin/rake db:migrate
It's first steps of github repo instructions

Cannon create vendor plugin

I am using Rails 3.2.2
In my project root command: rails generate plugin somename gives me error:
Could not find generator plugin
I can create only gem plugin.
Could somebody give me any advice?
The plugin generator has been removed as of release 3.2 (see here). Try this: rails plugin new my_plugin
If you need to digest how plugins created internally:
https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb line 170 initialize

RSpec and testing Rails Gem

I'm trying to set a testing framework for a rails engine.
I have everything working, I generated the corresponding rspec file with:
rails g rspec:install
However everytime I want to add a rspec testing file with:
rails g integration_test blah
The RSpec doesn't take over and instead the standard unit testing framework of rails creates the corresponding files. Any thoughts on where the problem might be?
I solved that problem running rails g with --integration-tools option
rails g integration_test blah --integration-tools=rspec
I do not know how to set rspec as default tool.
I always add in my application.rb :
config.generators do |g|
g.test_framework :rspec
end
That allows RSpec to replace Rails generator for tests.
you should put in application.rb:
config.generators do |g|
g.integration_tool :rspec
g.test_framework :rspec
end
source: rails configuration guide

Can you use RSpec, Shoulda, RCov?

I am attempting to get RCov to work with my RSpec and Shoulda test for a rails 3 app. It seems to work fine with my RSpec after using the Rake task below but all of the shoulda tests fail and I cant seem to find any documentation on getting these to work. They all run fine under autotest(rspec and shoulda).
namespace :spec do
desc "Run specs with RCov"
RSpec::Core::RakeTask.new('rcov' ) do |t|
#t.spec_files = FileList['spec/**/*_spec.rb' ]
t.rcov = true
t.rcov_opts = ['--exclude' , '\/Library\/Ruby' ]
end
end
What version of Ruby are you using?
I've found that Rcov doesn't work so well with Ruby 1.9, although last I checked was about 2 months ago.
I've switched over to cover_me, which is built on top of Rcov (I believe), and was built for Ruby 1.9.
I haven't had any problems with it so far, and it's easily installed.
Haven't tried it with Shoulda, but works great in Ruby 1.9, Rails 3, and Rspec 2.
Here's the link if you're interested: https://github.com/markbates/cover_me