A quick list of changes we've discovered in moving from RSpec 2 to RSpec 1. Some may produce deprecation warnings -- other changes simply fail the test. Please post anything you discover that's not on this list and I'll add it.
| RSpec 1.x | RSpec 2.x | 
|---|---|
| GENERAL | |
| @value.should be_close(300.0/72, 1e-4) | @value.should be_within(1e-4).of(300.0/72) | 
| CONTROLLER SPECS | |
| integrated_views | render_views | 
| reverse order of assertion and HTTP verb method: | |
| controller.should render_template("edit") get :edit, :name => "fred"  | get :edit, :name => "fred" response.should render_template("edit")  | 
| assigns[:instance_var].should | assigns(:instance_var).should | 
| parameter hash values can be numeric | parameter hash values must be strings | 
| put :update, :user_id => 3 | put :update, :user_id => "3" | 
| view template file not required | template file required or set expectation: controller.should_receive(:render) -- or stub it: controller.stub!(:render) | 
| VIEW SPECS | |
| assigns[:instance_var] = value | assign(:instance_var, value) | 
| response.body | rendered | 
| include_text | include | 
| have_tag | have_selector | 
| with_tag | have_selector | 
| :text | :content | 
| have_tag arguments don't need quotes | numbers or strings beginning with / must be quoted | 
| escape URL strings | do not escape URL strings | 
| response.should have_tag('form[action=/docs/111?id=44&x=1]') do with_tag 'input[type=hidden][name=x][value=55]' end  | |
|     rendered.should have_selector('form[action="/docs/111?id=44&x="1"]') do |tags| tags.should have_selector 'input[type=hidden][name=x][value="55"]' end  | |
| response.should have_tag('td') do with_tag 'span', :text => "Frank N. Stein" end  | |
|     rendered.should have_selector('td') do |tags| tags.should have_selector 'span', :content => "Frank N. Stein" end  | |
| For more information on changes from have_tag to have_selector, check this out. | |
| ROUTING SPECS | |
| {:get => 'all/data/in/db'}.should_not be_routeable | {:get => 'all/data/in/db'}.should_not be_routable | 
| route_for no longer supported | |
| assertions agains query parameters no longer supported: | |
| {:get => 'c/a?query_param=value'}.should route_to(:controller => 'c', :action => 'a', :query_param => 'value') | |
| {:get => 'c/a?query_param=value'}.should route_to(:controller => 'c', :action => 'a') | |
| MOCKS & STUBS | |
| stub_model(Widget, :new_record? => true) | stub_model(Widget).as_new_record | 
Great post, thanks!
ReplyDelete