LoginSignup
1

More than 5 years have passed since last update.

rails plugin new 躓いたところ

Last updated at Posted at 2017-08-11

これを参考にpluginを作ってみようと思ったが、全くチュートリアル通りにいかないので、困った。
railsにプルリクを送りたいが、ルールがめんどいし、英語できないから誰かお願いします。

  • rails 5.1.3
  • bundler 1.15.3
  • ruby 2.4.1

> 1.1 gem形式のプラグインを生成する

console
$ rails plugin new yaffle

動いた。

> 2 新しく生成したプラグインをテストする

console
$ cd yaffle
$ bundle install
You have one or more invalid gemspecs that need to be fixed.
The gemspec at ~/yaffle/yaffle.gemspec is not valid. Please fix this gemspec.
The validation error was '"FIXME" or "TODO" is not a description'

いきなりドキュメントの通りにいかない。ドキュメントにプルリク出したい。
以下対策。

yaffle.gemspec
@@ -9,9 +9,9 @@ Gem::Specification.new do |s|
   s.version     = Yaffle::VERSION
   s.authors     = ["user"]
   s.email       = ["xxx@example.com"]
-  s.homepage    = "TODO"
-  s.summary     = "TODO: Summary of Yaffle."
-  s.description = "TODO: Description of Yaffle."
+  s.homepage    = ""
+  s.summary     = "Summary of Yaffle."
+  s.description = "Description of Yaffle."
   s.license     = "MIT"

   s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
console
$ bundle install

成功

> 自動生成されたテストをrakeコマンドで実行します

console
$ bundle exec rake test
~/yaffle/test/dummy/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter ~/yaffle/test/dummy/config/application.rb to limit the frameworks that will be loaded.
# ...略...

よくわからないけどdummyプロジェクトのdbを作ってくればいいのかな。

console
$ cd test/dummy
$ bin rails db:migrate
$ cd -

リトライ

console
$ bundle exec rake test
~/yaffle/test/test_helper.rb:9:in `<top (required)>': uninitialized constant Rails::TestUnitReporter (NameError)

なんなんだよぉ〜これもぉー。github行って該当クラス調べたら定義はされているけどrequireされてないみたいなので、以下のように修正してみた。
ただし、railtiesの構造がよくわかっていないので、これで良いのか自信がない。

test_helper.rb
@@ -6,6 +6,7 @@ require "rails/test_help"
 # to be shown.
 Minitest.backtrace_filter = Minitest::BacktraceFilter.new

+require 'rails/test_unit/reporter'
 Rails::TestUnitReporter.executable = 'bin/test'

 # Load fixtures from the engine

リトライ

$ bundle exec rake test
Run options: --seed 10841

# Running:

.

Finished in 0.003075s, 325.2033 runs/s, 325.2033 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

やったー!

とりあえずここまで

何も始まっていないのに疲れてしまった!!

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1