Skip to content

Commit 2e4420d

Browse files
author
Sam Phippen
committed
Get cukes passing on 5.1
1 parent a8a50ae commit 2e4420d

File tree

7 files changed

+216
-14
lines changed

7 files changed

+216
-14
lines changed

Rakefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@ end
2929
Cucumber::Rake::Task.new(:cucumber) do |t|
3030
version = ENV.fetch("RAILS_VERSION", "~> 4.2.0")
3131
cucumber_flag = "--tags ~@rails_post_5"
32-
p version
33-
if /(^| )5(\.|-)0/ === version || version == "master"
34-
cucumber_flag = "--tags ~@rails_pre_5"
32+
tags = []
33+
if version.to_f >= 5.1
34+
tags << "~@rails_pre_5.1"
3535
end
3636

37+
if version.to_f >= 5.0
38+
tags << "~@rails_pre_5"
39+
end
40+
41+
if tags.empty?
42+
tags << "~@rails_post_5"
43+
end
44+
45+
cucumber_flag = tags.map { |tag| "--tag #{tag}" }
46+
3747
t.cucumber_opts = cucumber_flag
3848
end
3949

features/controller_specs/anonymous_controller.feature

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ Feature: anonymous controller
293293
When I run `rspec spec`
294294
Then the examples should all pass
295295

296+
@rails_pre_5
296297
Scenario: Invoke `around_filter` and `around_action` in base class
297298
Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with:
298299
"""ruby
@@ -324,6 +325,38 @@ Feature: anonymous controller
324325
When I run `rspec spec`
325326
Then the examples should all pass
326327

328+
@rails_post_5
329+
Scenario: Invoke `around_filter` and `around_action` in base class
330+
Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with:
331+
"""ruby
332+
require "rails_helper"
333+
334+
class ApplicationController < ActionController::Base
335+
around_action :an_around_filter
336+
337+
def an_around_filter
338+
@callback_invoked = true
339+
yield
340+
end
341+
end
342+
343+
RSpec.describe ApplicationController, :type => :controller do
344+
controller do
345+
def index
346+
render :plain => ""
347+
end
348+
end
349+
350+
it "invokes the callback" do
351+
get :index
352+
353+
expect(assigns[:callback_invoked]).to be_truthy
354+
end
355+
end
356+
"""
357+
When I run `rspec spec`
358+
Then the examples should all pass
359+
327360
@rails_pre_5
328361
Scenario: Anonymous controllers only create resource routes
329362
Given a file named "spec/controllers/application_controller_spec.rb" with:
@@ -610,7 +643,7 @@ Feature: anonymous controller
610643
611644
describe "#edit" do
612645
it "responds to GET" do
613-
get :edit, :id => "anyid"
646+
get :edit, :params => { :id => "anyid" }
614647
expect(response.body).to eq "edit called"
615648
end
616649
@@ -621,15 +654,15 @@ Feature: anonymous controller
621654
# And the rest...
622655
%w{get post put delete}.each do |calltype|
623656
it "responds to #{calltype}" do
624-
send(calltype, :edit, {:id => "anyid"})
657+
send(calltype, :edit, :params => {:id => "anyid"})
625658
expect(response.body).to eq "edit called"
626659
end
627660
end
628661
end
629662
630663
describe "#show" do
631664
it "responds to GET" do
632-
get :show, :id => "anyid"
665+
get :show, :params => { :id => "anyid" }
633666
expect(response.body).to eq "show called"
634667
end
635668
@@ -640,15 +673,15 @@ Feature: anonymous controller
640673
# And the rest...
641674
%w{get post put delete}.each do |calltype|
642675
it "responds to #{calltype}" do
643-
send(calltype, :show, {:id => "anyid"})
676+
send(calltype, :show, :params => {:id => "anyid"})
644677
expect(response.body).to eq "show called"
645678
end
646679
end
647680
end
648681
649682
describe "#update" do
650683
it "responds to PUT" do
651-
put :update, :id => "anyid"
684+
put :update, :params => { :id => "anyid" }
652685
expect(response.body).to eq "update called"
653686
end
654687
@@ -659,15 +692,15 @@ Feature: anonymous controller
659692
# And the rest...
660693
%w{get post put delete}.each do |calltype|
661694
it "responds to #{calltype}" do
662-
send(calltype, :update, {:id => "anyid"})
695+
send(calltype, :update, :params => {:id => "anyid"})
663696
expect(response.body).to eq "update called"
664697
end
665698
end
666699
end
667700
668701
describe "#destroy" do
669702
it "responds to DELETE" do
670-
delete :destroy, :id => "anyid"
703+
delete :destroy, :params => { :id => "anyid" }
671704
expect(response.body).to eq "destroy called"
672705
end
673706
@@ -678,7 +711,7 @@ Feature: anonymous controller
678711
# And the rest...
679712
%w{get post put delete}.each do |calltype|
680713
it "responds to #{calltype}" do
681-
send(calltype, :destroy, {:id => "anyid"})
714+
send(calltype, :destroy, :params => {:id => "anyid"})
682715
expect(response.body).to eq "destroy called"
683716
end
684717
end

features/controller_specs/controller_spec.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Feature: controller spec
3434
When I run `rspec spec`
3535
Then the example should pass
3636

37+
@rails_pre_5
3738
Scenario: setting a different content type for example json (request type)
3839
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
3940
"""ruby
@@ -55,3 +56,26 @@ Feature: controller spec
5556
"""
5657
When I run `rspec spec`
5758
Then the example should pass
59+
60+
@rails_post_5
61+
Scenario: setting a different content type for example json (request type)
62+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
63+
"""ruby
64+
require "rails_helper"
65+
66+
RSpec.describe WidgetsController, :type => :controller do
67+
describe "responds to" do
68+
it "responds to html by default" do
69+
post :create, :params => { :widget => { :name => "Any Name" } }
70+
expect(response.content_type).to eq "text/html"
71+
end
72+
73+
it "responds to custom formats when provided in the params" do
74+
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
75+
expect(response.content_type).to eq "application/json"
76+
end
77+
end
78+
end
79+
"""
80+
When I run `rspec spec`
81+
Then the example should pass

features/feature_specs/feature_spec.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Feature: Feature spec
2020
[customer](http://c2.com/cgi/wiki?CustomerTest) and [acceptance](http://c2.com/cgi/wiki?AcceptanceTest) tests. When capybara is required it sets
2121
`:type => :feature` automatically for you.
2222

23+
@rails_pre_5.1
2324
Scenario: Feature specs are skipped without Capybara
2425
Given a file named "spec/features/widget_management_spec.rb" with:
2526
"""ruby
@@ -58,7 +59,6 @@ Feature: Feature spec
5859
scenario "User creates a new widget" do
5960
visit "/widgets/new"
6061
61-
fill_in "Name", :with => "My Widget"
6262
click_button "Create Widget"
6363
6464
expect(page).to have_text("Widget was successfully created.")

features/matchers/have_http_status_matcher.feature

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Feature: `have_http_status` matcher
100100
When I run `rspec spec/controllers/gadgets_spec.rb`
101101
Then the examples should all pass
102102

103+
@rails_pre_5
103104
Scenario: Using in a request spec
104105
Given a file named "spec/requests/gadgets/widget_management_spec.rb" with:
105106
"""ruby
@@ -124,6 +125,31 @@ Feature: `have_http_status` matcher
124125
When I run `rspec spec/requests`
125126
Then the examples should all pass
126127

128+
@rails_post_5
129+
Scenario: Using in a request spec
130+
Given a file named "spec/requests/gadgets/widget_management_spec.rb" with:
131+
"""ruby
132+
require "rails_helper"
133+
134+
RSpec.describe "Widget management", :type => :request do
135+
136+
it "creates a Widget and redirects to the Widget's page" do
137+
get "/widgets/new"
138+
expect(response).to have_http_status(:ok)
139+
140+
post "/widgets", :params => { :widget => {:name => "My Widget"} }
141+
expect(response).to have_http_status(302)
142+
143+
follow_redirect!
144+
145+
expect(response).to have_http_status(:success)
146+
end
147+
148+
end
149+
"""
150+
When I run `rspec spec/requests`
151+
Then the examples should all pass
152+
127153
@capybara
128154
Scenario: Using in a feature spec
129155
Given a file named "spec/features/widget_management_spec.rb" with:
@@ -136,7 +162,6 @@ Feature: `have_http_status` matcher
136162
visit "/widgets/new"
137163
expect(page).to have_http_status(200)
138164
139-
fill_in "Name", :with => "My Widget"
140165
click_button "Create Widget"
141166
142167
expect(page).to have_http_status(:success)

features/matchers/redirect_to_matcher.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Feature: redirect_to matcher
77
It is available in controller specs (spec/controllers) and request
88
specs (spec/requests).
99

10+
@rails_pre_5
1011
Scenario: redirect_to with four possible options
1112
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
1213
"""ruby
@@ -38,3 +39,36 @@ Feature: redirect_to matcher
3839
"""
3940
When I run `rspec spec/controllers/widgets_controller_spec.rb`
4041
Then the examples should all pass
42+
43+
@rails_post_5
44+
Scenario: redirect_to with four possible options
45+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
46+
"""ruby
47+
require "rails_helper"
48+
49+
RSpec.describe WidgetsController do
50+
51+
describe "#create" do
52+
subject { post :create, :params => { :widget => { :name => "Foo" } } }
53+
54+
it "redirects to widget_url(@widget)" do
55+
expect(subject).to redirect_to(widget_url(assigns(:widget)))
56+
end
57+
58+
it "redirects_to :action => :show" do
59+
expect(subject).to redirect_to :action => :show,
60+
:id => assigns(:widget).id
61+
end
62+
63+
it "redirects_to(@widget)" do
64+
expect(subject).to redirect_to(assigns(:widget))
65+
end
66+
67+
it "redirects_to /widgets/:id" do
68+
expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}")
69+
end
70+
end
71+
end
72+
"""
73+
When I run `rspec spec/controllers/widgets_controller_spec.rb`
74+
Then the examples should all pass

features/request_specs/request_spec.feature

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Feature: request spec
2626
request specs as of Capybara 2.0.0. The recommended way to use Capybara is
2727
with [feature specs](../feature-specs/feature-spec).
2828

29+
@rails_pre_5
2930
Scenario: specify managing a Widget with Rails integration methods
3031
Given a file named "spec/requests/widget_management_spec.rb" with:
3132
"""ruby
@@ -55,7 +56,38 @@ Feature: request spec
5556
When I run `rspec spec/requests/widget_management_spec.rb`
5657
Then the example should pass
5758

58-
@unsupported-on-rails-3-0
59+
@rails_post_5
60+
Scenario: specify managing a Widget with Rails integration methods
61+
Given a file named "spec/requests/widget_management_spec.rb" with:
62+
"""ruby
63+
require "rails_helper"
64+
65+
RSpec.describe "Widget management", :type => :request do
66+
67+
it "creates a Widget and redirects to the Widget's page" do
68+
get "/widgets/new"
69+
expect(response).to render_template(:new)
70+
71+
post "/widgets", :params => { :widget => {:name => "My Widget"} }
72+
73+
expect(response).to redirect_to(assigns(:widget))
74+
follow_redirect!
75+
76+
expect(response).to render_template(:show)
77+
expect(response.body).to include("Widget was successfully created.")
78+
end
79+
80+
it "does not render a different template" do
81+
get "/widgets/new"
82+
expect(response).to_not render_template(:show)
83+
end
84+
end
85+
"""
86+
When I run `rspec spec/requests/widget_management_spec.rb`
87+
Then the example should pass
88+
89+
90+
@unsupported-on-rails-3-0 @rails_pre_5
5991
Scenario: requesting a JSON response
6092
Given a file named "spec/requests/widget_management_spec.rb" with:
6193
"""ruby
@@ -79,6 +111,31 @@ Feature: request spec
79111
When I run `rspec spec/requests/widget_management_spec.rb`
80112
Then the example should pass
81113

114+
@rails_post_5
115+
Scenario: requesting a JSON response
116+
Given a file named "spec/requests/widget_management_spec.rb" with:
117+
"""ruby
118+
require "rails_helper"
119+
120+
RSpec.describe "Widget management", :type => :request do
121+
122+
it "creates a Widget" do
123+
headers = {
124+
"ACCEPT" => "application/json", # This is what Rails 4 accepts
125+
"HTTP_ACCEPT" => "application/json" # This is what Rails 3 accepts
126+
}
127+
post "/widgets", :params => { :widget => {:name => "My Widget"} }, :headers => headers
128+
129+
expect(response.content_type).to eq("application/json")
130+
expect(response).to have_http_status(:created)
131+
end
132+
133+
end
134+
"""
135+
When I run `rspec spec/requests/widget_management_spec.rb`
136+
Then the example should pass
137+
138+
@rails_pre_5
82139
Scenario: providing JSON data
83140
Given a file named "spec/requests/widget_management_spec.rb" with:
84141
"""ruby
@@ -96,3 +153,22 @@ Feature: request spec
96153
"""
97154
When I run `rspec spec/requests/widget_management_spec.rb`
98155
Then the example should pass
156+
157+
@rails_post_5
158+
Scenario: providing JSON data
159+
Given a file named "spec/requests/widget_management_spec.rb" with:
160+
"""ruby
161+
require "rails_helper"
162+
163+
RSpec.describe "Widget management", :type => :request do
164+
165+
it "creates a Widget and redirects to the Widget's page" do
166+
headers = { "CONTENT_TYPE" => "application/json" }
167+
post "/widgets", :params => '{ "widget": { "name":"My Widget" } }', :headers => headers
168+
expect(response).to redirect_to(assigns(:widget))
169+
end
170+
171+
end
172+
"""
173+
When I run `rspec spec/requests/widget_management_spec.rb`
174+
Then the example should pass

0 commit comments

Comments
 (0)