Visitar URL original
Capybara: add specs for js tests (#926) · stringer-rss/stringer@1774262 · GitHub
Skip to content

Commit 1774262

Browse files
authored
Capybara: add specs for js tests (#926)
1 parent 5939cb4 commit 1774262

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎config/routes.rb‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
match("/stories/:id", to: "stories#update", via: :put)
2929
match("/stories/mark_all_as_read", to: "stories#mark_all_as_read", via: :post)
3030

31-
if ENV["RACK_ENV"] == "development"
31+
unless Rails.env.production?
3232
require_relative "../spec/javascript/test_controller"
3333

3434
match("/test", to: "test#index", via: :get)
35-
match("/spec/*", to: "test#spec", via: :get)
36-
match("/vendor/*", to: "test#vendor", via: :get)
35+
match("/spec/*splat", to: "test#spec", via: :get)
36+
match("/vendor/js/*splat", to: "test#vendor", via: :get)
37+
match("/vendor/css/*splat", to: "test#vendor", via: :get)
3738
end
3839
end

‎spec/javascript/spec/models/story_spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
RSpec.describe("Story", function(){
3+
describe("Story", function(){
44
it("should exist", function(){
55
Story.should.exist;
66
});

‎spec/javascript/spec/views/story_view_spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
RSpec.describe("Storyiew", function(){
3+
describe("Storyiew", function(){
44
it("should exist", function(){
55
StoryView.should.exist;
66
});

‎spec/javascript/test_controller.rb‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
class TestController < ApplicationController
4+
skip_before_action :verify_authenticity_token
5+
46
def index
57
authorization.skip
68
prepend_view_path(test_path("support", "views"))
@@ -9,12 +11,14 @@ def index
911

1012
def spec
1113
authorization.skip
12-
send_file(test_path("spec", *params[:splat]))
14+
send_file(test_path("spec", "#{params[:splat]}.js"))
1315
end
1416

1517
def vendor
1618
authorization.skip
17-
send_file(test_path("support", "vendor", *params[:splat]))
19+
20+
filename = "#{params[:splat]}.#{params[:format]}"
21+
send_file(test_path("support", "vendor", params[:format], filename))
1822
end
1923

2024
private

‎spec/system/js_tests_spec.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "JS tests" do
4+
it "passes the mocha tests" do
5+
login_as(default_user)
6+
7+
visit "/test"
8+
9+
expect(page).to have_content("failures: 0")
10+
end
11+
end

0 commit comments

Comments
 (0)