[rspec-users] Notes on upgrading from RSpec 1 to RSpec 2

20 views
Skip to first unread message

Jim Morris

unread,
Dec 4, 2010, 6:22:26 PM12/4/10
to rspec...@rubyforge.org
I am trying to upgrade a Rails 2.2.2 app to Rails3, its a pain ;)

Part of this is I need to upgrade all my Specs to RSpec2, as this info
does not seem to be in any one place, here is a summary of what I
needed to do...

* needed to rename all my views from .haml to .html.haml,
(or .html.erb) although
Rails3 seemed ok with the old naming RSpec2 view specs failed to
find the templates with the old name.

* rewrite all my view specs...
- change `@controller.template.` to `view.`

- change `have_tag` to `have_selector` and change the parameters
- place holders not supported, need to use #{}
- add :content => for any text in second parameter

- change `assign[:blah]= :blod` to `assign(:blag, :blod)`

- change the describe ... do to have the path to the view rather
than text description

- change the render '/show' to just render or render :file => 'full
template spec'

- change have_text to matches(/../)

- change response.should to rendered.shoul

* modify the controller specs
- controller_name is no longer supported, so need to nest all my
describes under a top level describe that has the controller
name.
describe 'UsersController' do
or use subject {SomeController.new} (not tested yet)

- when using post/delete/put :something, :id => 1 passing in an
integer id used to work, now it needs to
be a string (probably a rails3 thing)
delete :destroy, :id => "1"

* helper specs only needed minor changes
- change have_tag to have_selector


_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Kurt

unread,
Jan 13, 2011, 1:36:50 PM1/13/11
to rspec...@rubyforge.org
Hi -- Thanks for sharing all your tips. I couldn't understand your
line about what replaces have_text, however. I don't see a method
called "matches" or "match"...

I think your list might be the start of an effort by users to document
RSpec2 the hard way, since a lot has changed that the core team has
not documented anywhere. We've found that the Rails3 upgrade is some
work, but the advantages over Rails 2 are clear. RSpec2, however, is
so poorly documented, useful features have been removed for no
apparent reason, and any advantages over RSpec1 have not become clear
yet (our test suite runs 3 times slower than it did in RSpec1!).

On Dec 4 2010, 3:22 pm, Jim Morris <wolfma...@gmail.com> wrote:
> I am trying to upgrade a Rails 2.2.2 app to Rails3, its  a pain ;)
>
> Part of this is I need to upgrade all my Specs to RSpec2, as this info
> does not seem to be in any one place, here is a summary of what I
> needed to do...
>
> * needed to rename all my views from .haml to .html.haml,
> (or .html.erb) although
>   Rails3 seemed ok with the old naming RSpec2 view specs failed to
> find the templates with the old name.
>
> * rewrite all my view specs...

>   - change `...@controller.template.` to `view.`


>
>   -  change `have_tag` to `have_selector` and change the parameters
>      - place holders not supported, need to use #{}
>      - add :content => for any text in second parameter
>
>   - change `assign[:blah]= :blod` to `assign(:blag, :blod)`
>
>   - change the describe ... do to have the path to the view rather
> than text description
>
>   - change the render '/show' to just render or render :file => 'full
> template spec'
>

>   - changehave_textto matches(/../)


>
>   - change response.should to rendered.shoul
>
> * modify the controller specs
>   - controller_name is no longer supported, so need to nest all my
>     describes under a top level describe that has the controller
> name.
>      describe 'UsersController' do
>      or use subject {SomeController.new}  (not tested yet)
>
>    - when using post/delete/put :something, :id => 1 passing in an
> integer id used to work, now it needs to
>      be a string (probably a rails3 thing)
>      delete :destroy, :id => "1"
>
> * helper specs only needed minor changes
>   - change have_tag to have_selector
>
> _______________________________________________
> rspec-users mailing list

> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

David Chelimsky

unread,
Jan 13, 2011, 2:11:36 PM1/13/11
to rspec-users
On Jan 13, 2011, at 12:36 PM, Kurt wrote:

> Hi -- Thanks for sharing all your tips. I couldn't understand your
> line about what replaces have_text, however. I don't see a method
> called "matches" or "match"...
>
> I think your list might be the start of an effort by users to document
> RSpec2 the hard way, since a lot has changed that the core team has
> not documented anywhere. We've found that the Rails3 upgrade is some
> work, but the advantages over Rails 2 are clear. RSpec2, however, is
> so poorly documented, useful features have been removed for no
> apparent reason, and any advantages over RSpec1 have not become clear
> yet (our test suite runs 3 times slower than it did in RSpec1!).

re: speed, you be sure to upgrade to rspec-rails-2.2 (I'd go for the latest, 2.4.1), which sped things up considerably.

As for docs - official docs are at http://relishapp.com/rspec.

Info about contributing to the docs can be found there and at http://blog.davidchelimsky.net/2010/12/23/rspec-2-documentation-2/.

Thanks in advance for your help.

Cheers,
David

Jim Morris

unread,
Jan 13, 2011, 3:35:16 PM1/13/11
to rspec...@rubyforge.org
On Jan 13, 10:36 am, Kurt <k...@cissor.com> wrote:
> Hi -- Thanks for sharing all your tips.  I couldn't understand your
> line about what replaces have_text, however.  I don't see a method
> called "matches" or "match"...

Sorry that should be...

response.body.should match(/../)

it is the standard text regexp match.

also

response.body.should =~ /.../

should work too.

Kurt

unread,
Feb 1, 2011, 5:23:55 PM2/1/11
to rspec...@rubyforge.org
I've started a chart of differences between RSpec 1 and 2 here:
http://snyderscribbles.blogspot.com/2011/01/rspec-2-changes-from-rspec-1.html

I'll gladly post any new discoveries anyone want to contribute.

On Dec 4 2010, 3:22 pm, Jim Morris <wolfma...@gmail.com> wrote:

> I am trying to upgrade a Rails 2.2.2app to Rails3, its  a pain ;)


>
> Part of this is I need to upgrade all my Specs to RSpec2, as this info
> does not seem to be in any one place, here is a summary of what I
> needed to do...
>
> * needed to rename all my views from .haml to .html.haml,
> (or .html.erb) although
>   Rails3 seemed ok with the old naming RSpec2 view specs failed to
> find the templates with the old name.
>
> * rewrite all my view specs...

>   - change `...@controller.template.` to `view.`


>
>   -  change `have_tag` to `have_selector` and change the parameters
>      - place holders not supported, need to use #{}
>      - add :content => for any text in second parameter
>
>   - change `assign[:blah]= :blod` to `assign(:blag, :blod)`
>
>   - change the describe ... do to have the path to the view rather
> than text description
>
>   - change the render '/show' to just render or render :file => 'full
> template spec'
>
>   - change have_text to matches(/../)
>
>   - change response.should to rendered.shoul
>
> * modify the controller specs
>   - controller_name is no longer supported, so need to nest all my
>     describes under a top level describe that has the controller
> name.
>      describe 'UsersController' do
>      or use subject {SomeController.new}  (not tested yet)
>
>    - when using post/delete/put :something, :id => 1 passing in an
> integer id used to work, now it needs to
>      be a string (probably a rails3 thing)
>      delete :destroy, :id => "1"
>
> * helper specs only needed minor changes
>   - change have_tag to have_selector
>

> _______________________________________________rspec-users mailing listrspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

Kurt

unread,
Feb 1, 2011, 5:31:26 PM2/1/11
to rspec...@rubyforge.org
Most of our RSpec2 conversion has been done since version 2.4, so my
report of performance 2-3 times slower than RSpec 1 is based on those
releases.

On Jan 13, 11:11 am, David Chelimsky <dchelim...@gmail.com> wrote:
> On Jan 13, 2011, at 12:36 PM, Kurt wrote:
>
> > Hi -- Thanks for sharing all your tips.  I couldn't understand your
> > line about what replaces have_text, however.  I don't see a method
> > called "matches" or "match"...
>
> > I think your list might be the start of an effort by users to document

> >RSpec2the hard way, since a lot has changed that the core team has
> > not documented anywhere.  We've found that the Rails3upgradeis some


> > work, but the advantages over Rails 2 are clear.  RSpec2, however, is
> > so poorly documented, useful features have been removed for no
> > apparent reason, and any advantages over RSpec1 have not become clear
> > yet (our test suite runs 3 times slower than it did in RSpec1!).
>

> re: speed, you be sure toupgradeto rspec-rails-2.2 (I'd go for the latest, 2.4.1), which sped things up considerably.
>
> As for docs - official docs are athttp://relishapp.com/rspec.
>
> Info about contributing to the docs can be found there and athttp://blog.davidchelimsky.net/2010/12/23/rspec-2-documentation-2/.


>
> Thanks in advance for your help.
>
> Cheers,
> David
>
>
>
> > On Dec 4 2010, 3:22 pm, Jim Morris <wolfma...@gmail.com> wrote:

> >> I am trying toupgradea Rails 2.2.2 app to Rails3, its  a pain ;)
>
> >> Part of this is I need toupgradeall my Specs toRSpec2, as this info


> >> does not seem to be in any one place, here is a summary of what I
> >> needed to do...
>
> >> * needed to rename all my views from .haml to .html.haml,
> >> (or .html.erb) although

> >>   Rails3 seemed ok with the old namingRSpec2view specs failed to

> > rspec-us...@rubyforge.org

David Chelimsky

unread,
Feb 1, 2011, 6:17:57 PM2/1/11
to rspec-users
On Feb 1, 2011, at 4:23 PM, Kurt wrote:

> I've started a chart of differences between RSpec 1 and 2 here:
> http://snyderscribbles.blogspot.com/2011/01/rspec-2-changes-from-rspec-1.html
>
> I'll gladly post any new discoveries anyone want to contribute.

It would be great if you would contribute these directly to RSpec's docs so everyone can find them and benefit from them. Take a look at:

http://relishapp.com/rspec/rspec-core/v/2-4/file/upgrade
http://relishapp.com/rspec/rspec-rails/v/2-4/file/upgrade

They are just Markdown files, maintained in the rspec projects:

https://github.com/rspec/rspec-core/blob/master/features/Upgrade.md
https://github.com/rspec/rspec-rails/blob/master/features/Upgrade.md

Just submit pull requests and I'll be happy to merge them.

Cheers,
David

David Chelimsky

unread,
Feb 1, 2011, 6:12:17 PM2/1/11
to rspec-users
On Feb 1, 2011, at 4:31 PM, Kurt wrote:

> Most of our RSpec2 conversion has been done since version 2.4, so my
> report of performance 2-3 times slower than RSpec 1 is based on those
> releases.

Are you sure that's all RSpec? rspec-core-2.2 actually runs faster than rspec-core-1.x, and a lot of the Rails framework changed as well. And don't forget bundler. There are a lot of moving parts here, so if you can isolate the slow down to RSpec, please let us know what you find so we can address any specific issues.

Thanks!

David

Kurt

unread,
Feb 2, 2011, 12:31:29 PM2/2/11
to rs...@googlegroups.com, rspec-users
We haven't had the time to try to isolate the cause of the slowdown, but whatever the cause, it seems to be widespread as I have seen others reporting slowdowns of the same magnitude we have experienced.  Our suite of 700 tests used to run in about 1 minute and on the same machine, with the minimal implementation and spec changes required to move to the newer versions, they now take about 3 minutes.  What performance differences have you seen in the shift from RSpec1/Rails2 to RSpec2/Rails3? 
Reply all
Reply to author
Forward
0 new messages