質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

1890閲覧

everydayrails2章のセットアップがうまくいきません。(Could not find shared context "project setup")

yamatotto

総合スコア5

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/09/24 21:49

編集2020/09/24 22:10

前提・実現したいこと

Cloud9を使用して、『Everyday Rails - RSpecによるRailsテスト入門』の環境構築をしたいと思っています。ただ、書籍と同じような手順を行っても、エラーが出てしまい、困っています。

以下、手順
1 everydayrailsのコードをクローン
2 bundle install
3 bin/rails db:create:allでデータベース作成
4 bun/rspecでテスト←ここでエラーが出る

発生している問題・エラーメッセージ

ec2-user:~/environment/everydayrails-rspec-2017 (master) $ bin/rspec /home/ec2-user/.rvm/gems/ruby-2.6.3/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:273: warning: BigDecimal.new is deprecated; use BigDecimal() method instead. Running via Spring preloader in process 15131 /home/ec2-user/.rvm/gems/ruby-2.6.3/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:273: warning: BigDecimal.new is deprecated; use BigDecimal() method instead. An error occurred while loading ./spec/controllers/tasks_controller_spec.rb. Failure/Error: include_context "project setup" ArgumentError: Could not find shared context "project setup" # ./spec/controllers/tasks_controller_spec.rb:4:in `block in <top (required)>' # ./spec/controllers/tasks_controller_spec.rb:3:in `<top (required)>' # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call' # -e:1:in `<main>' Finished in 0.00038 seconds (files took 3.23 seconds to load) 0 examples, 0 failures, 1 error occurred outside of examples

該当のソースコード

Gemfile

1source 'https://rubygems.org' 2 3git_source(:github) do |repo_name| 4 repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 "https://github.com/#{repo_name}.git" 6end 7 8gem 'rails', '~> 5.1.1' 9gem 'sqlite3' 10gem 'puma', '~> 3.7' 11gem 'sass-rails', '~> 5.0' 12gem 'uglifier', '>= 1.3.0' 13gem 'coffee-rails', '~> 4.2' 14gem 'turbolinks', '~> 5' 15gem 'jbuilder', '~> 2.5' 16 17group :development, :test do 18 gem 'rspec-rails', '~> 3.8.0' 19 gem 'factory_bot_rails', '~> 4.10.0' 20 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 21end 22 23group :development do 24 gem 'web-console', '>= 3.3.0' 25 gem 'listen', '>= 3.0.5', '< 3.2' 26 gem 'spring' 27 gem 'spring-watcher-listen', '~> 2.0.0' 28 gem 'faker', require: false # for sample data in development 29 gem 'spring-commands-rspec' 30end 31 32group :test do 33 gem 'capybara', '~> 2.15.4' 34 gem 'selenium-webdriver' 35 gem 'chromedriver-helper' 36 # Or use poltergeist and PhantomJS as an alternative to Selenium/Chrome 37 # gem 'poltergeist', '~> 1.15.0' 38 gem 'launchy', '~> 2.4.3' 39 gem 'shoulda-matchers', 40 git: 'https://github.com/thoughtbot/shoulda-matchers.git', 41 branch: 'rails-5' 42 gem 'vcr' 43 gem 'webmock' 44end 45 46gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 47 48gem 'bootstrap-sass' 49gem 'jquery-rails' 50gem 'devise' 51gem 'paperclip' 52gem 'geocoder' 53
require 'rails_helper' RSpec.describe TasksController, type: :controller do include_context "project setup" describe "#show" do it "responds with JSON formatted output" do sign_in user get :show, format: :json, params: { project_id: project.id, id: task.id } expect(response).to have_content_type :json end end describe "#create" do it "responds with JSON formatted output" do new_task = { name: "New test task" } sign_in user post :create, format: :json, params: { project_id: project.id, task: new_task } expect(response).to have_content_type :json end it "adds a new task to the project" do new_task = { name: "New test task" } sign_in user expect { post :create, format: :json, params: { project_id: project.id, task: new_task } }.to change(project.tasks, :count).by(1) end it "requires authentication" do new_task = { name: "New test task" } # Don't sign in this time ... expect { post :create, format: :json, params: { project_id: project.id, task: new_task } }.to_not change(project.tasks, :count) expect(response).to_not be_success end end end

補足情報(FW/ツールのバージョンなど)

環境
Cloud9(Amazon linux)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

no1knows

2020/09/25 00:36

RSpec.shared_context "project setup" do ... endは記載されている前提でしょうか?
yamatotto

2020/09/25 03:47

spec/support/contexts/project_setup.rbというファイルの中に、記載されているのを確認しました。
guest

回答1

0

自己解決

gemのバージョンが違うようでした。

投稿2020/09/25 03:58

yamatotto

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問