Skip to content
This repository was archived by the owner on May 29, 2020. It is now read-only.

Commit 03142d0

Browse files
committed
spec green
1 parent 1e1d9fb commit 03142d0

40 files changed

+180
-150
lines changed

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
--color
2+
--warnings
3+
--require spec_helper

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565

6666
group :development, :test do
6767
gem "rspec-rails"
68-
gem "webrat"
68+
gem "capybara"
6969
gem 'spring'
7070
gem 'sqlite3'
7171
gem 'ci_reporter'

Gemfile.lock

+9-5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ GEM
5959
binding_of_caller (0.7.2)
6060
debug_inspector (>= 0.0.1)
6161
builder (3.2.2)
62+
capybara (2.4.1)
63+
mime-types (>= 1.16)
64+
nokogiri (>= 1.3.3)
65+
rack (>= 1.0.0)
66+
rack-test (>= 0.5.4)
67+
xpath (~> 2.0)
6268
celluloid (0.15.2)
6369
timers (~> 1.1.0)
6470
ci_reporter (1.9.2)
@@ -267,11 +273,9 @@ GEM
267273
unf (0.1.4)
268274
unf_ext
269275
unf_ext (0.0.6)
270-
webrat (0.7.3)
271-
nokogiri (>= 1.2.0)
272-
rack (>= 1.0)
273-
rack-test (>= 0.5.3)
274276
webrobots (0.1.1)
277+
xpath (2.0.0)
278+
nokogiri (~> 1.3)
275279

276280
PLATFORMS
277281
ruby
@@ -283,6 +287,7 @@ DEPENDENCIES
283287
better_errors
284288
binding_of_caller
285289
cancan!
290+
capybara
286291
ci_reporter
287292
dalli
288293
exception_notification
@@ -313,4 +318,3 @@ DEPENDENCIES
313318
turbolinks
314319
twitter-bootstrap-rails
315320
uglifier (>= 1.0.3)
316-
webrat

app/models/post.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def cache_key
3131
# returns the cached comments if comments are cached,
3232
# otherwise gets comments from DB and caches and returns them
3333
def cached_comments
34-
Rails.cache.fetch([self, 'comments']) { comments.to_a }
34+
Rails.cache.fetch([self, 'comments']) { comments.to_a }
3535
end
3636

3737
# clear all cache belongs to self

config/boot.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Set up gems listed in the Gemfile.
22
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
33

4-
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

lib/templates/rspec/controller/controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
<% module_namespacing do -%>
44
describe <%= class_name %>Controller do

lib/templates/rspec/controller/view_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>" do
44
before do

lib/templates/rspec/integration/request_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe "<%= class_name.pluralize %>" do
44
describe "GET /<%= table_name %>" do

lib/templates/rspec/scaffold/controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# This spec was generated by rspec-rails when you ran the scaffold generator.
44
# It demonstrates how one might use RSpec to specify the controller code that

lib/templates/rspec/scaffold/edit_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/edit" do

lib/templates/rspec/scaffold/index_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/index" do

lib/templates/rspec/scaffold/new_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/new" do

lib/templates/rspec/scaffold/show_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
describe "<%= ns_table_name %>/show" do

spec/controllers/comments_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# This spec was generated by rspec-rails when you ran the scaffold generator.
44
# It demonstrates how one might use RSpec to specify the controller code that

spec/controllers/posts_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# This spec was generated by rspec-rails when you ran the scaffold generator.
44
# It demonstrates how one might use RSpec to specify the controller code that

spec/controllers/sessions_controller_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe SessionsController do
44
let(:valid_attributes){ FactoryGirl.attributes_for(:user) }
@@ -21,7 +21,7 @@
2121
expect(subject).to redirect_to(root_url)
2222
end
2323
it "resets session" do
24-
ActionDispatch::Request.any_instance.should_receive(:reset_session).once
24+
expect_any_instance_of(ActionDispatch::Request).to receive(:reset_session).once
2525
subject
2626
end
2727
end

spec/controllers/users_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# This spec was generated by rspec-rails when you ran the scaffold generator.
44
# It demonstrates how one might use RSpec to specify the controller code that

spec/helpers/comments_helper_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# Specs in this file have access to a helper object that includes
44
# the CommentsHelper. For example:

spec/helpers/posts_helper_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# Specs in this file have access to a helper object that includes
44
# the PostsHelper. For example:

spec/helpers/sessions_helper_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# Specs in this file have access to a helper object that includes
44
# the SessionsHelper. For example:

spec/helpers/users_helper_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
# Specs in this file have access to a helper object that includes
44
# the UsersHelper. For example:

spec/models/comment_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe Comment do
44
#pending "add some examples to (or delete) #{__FILE__}"

spec/models/post_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe Post do
44
subject(:post){ FactoryGirl.create(:post) }
@@ -19,7 +19,7 @@
1919
end
2020
context 'before caching' do
2121
it 'gets comments from DB' do
22-
@post.should_receive(:comments).once
22+
expect(@post).to receive(:comments).once
2323
@post.cached_comments
2424
end
2525
it 'stores comments into cache' do
@@ -34,7 +34,7 @@
3434
@post = Post.find(@post.id)
3535
end
3636
it 'gets comments from cache' do
37-
@post.should_receive(:comments).never
37+
expect(@post).to receive(:comments).never
3838
@post.cached_comments
3939
end
4040
it 'returns correct comments' do

spec/models/user_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe User do
44
subject(:user){ FactoryGirl.create(:user) }
55
describe "password validation" do
66
context "on create" do
77
it "fail if length is 5" do
88
user = FactoryGirl.build(:user, password: "hogeh")
9-
expect(user.save).to be_false
9+
expect(user.save).to eq false
1010
expect(user.errors[:password]).not_to be_nil
1111
end
1212
end
@@ -21,16 +21,16 @@
2121
end
2222
it "success with valid password and confirmation" do
2323
user.assign_attributes(password: "hogeho", password_confirmation: "hogeho")
24-
expect(user.save).to be_true
24+
expect(user.save).to eq true
2525
end
2626
it "fail if confirmation is invalid" do
2727
user.assign_attributes(password: "hogeho", password_confirmation: "")
28-
expect(user.save).to be_false
28+
expect(user.save).to eq false
2929
expect(user.errors[:password]).not_to be_nil
3030
end
3131
it "fail if length is 5" do
3232
user.assign_attributes(password: "hogeh", password_confirmation: "hogeh")
33-
expect(user.save).to be_false
33+
expect(user.save).to eq false
3434
expect(user.errors[:password]).not_to be_nil
3535
end
3636
end

spec/rails_helper.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file is copied to spec/ when you run 'rails generate rspec:install'
2+
ENV["RAILS_ENV"] ||= 'test'
3+
require 'spec_helper'
4+
require File.expand_path("../../config/environment", __FILE__)
5+
require 'rspec/rails'
6+
7+
# Requires supporting ruby files with custom matchers and macros, etc, in
8+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
9+
# run as spec files by default. This means that files in spec/support that end
10+
# in _spec.rb will both be required and run as specs, causing the specs to be
11+
# run twice. It is recommended that you do not name files matching this glob to
12+
# end with _spec.rb. You can configure this pattern with with the --pattern
13+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
14+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
15+
16+
# Checks for pending migrations before tests are run.
17+
# If you are not using ActiveRecord, you can remove this line.
18+
ActiveRecord::Migration.maintain_test_schema!
19+
20+
RSpec.configure do |config|
21+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
22+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
23+
24+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
25+
# examples within a transaction, remove the following line or assign false
26+
# instead of true.
27+
config.use_transactional_fixtures = true
28+
29+
# RSpec Rails can automatically mix in different behaviours to your tests
30+
# based on their file location, for example enabling you to call `get` and
31+
# `post` in specs under `spec/controllers`.
32+
#
33+
# You can disable this behaviour by removing the line below, and instead
34+
# explicitly tag your specs with their type, e.g.:
35+
#
36+
# RSpec.describe UsersController, :type => :controller do
37+
# # ...
38+
# end
39+
#
40+
# The different available types are documented in the features, such as in
41+
# https://relishapp.com/rspec/rspec-rails/docs
42+
config.infer_spec_type_from_file_location!
43+
end

spec/requests/comments_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe "Comments" do
44
before do

spec/requests/posts_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe "Posts" do
44
before do

spec/requests/users_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'rails_helper'
22

33
describe "Users" do
44
before do

0 commit comments

Comments
 (0)