6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gem作ってGithubに配置するまで(RubyGems.orgへのpush除く)

Last updated at Posted at 2014-07-28

概要

初Githubリポジトリ作成。だったので、備忘録的にまとめておく。
bundlerでgemの雛形作成~Githubにpushするまでについて書く。
それ以降はFacebookとの通信をmockするgemを作ってみたを参照。

ちなみに、作ったgemはこちら > ogawatti/facemock

やったこと

  1. Githubにリポジトリ作成
  2. bundlerでgemの雛形作成
  3. First Commit & push

Githubにリポジトリを作成

Githubのアカウント取得は省略。
push先のリポジトリを作っておく。

  1. Githubにログインして右上の「+」ボタンから「New repository」を選択
  2. リポジトリ情報のうち以下を埋めて「Create repository」を押下
  • Repository name : facemock
  • public を選択
  1. リポジトリ作成される
  • 最初にinitしてREADME作れ~と言われるが、gem雛形pushするので放っておく

Gemの雛形を作成する

まずは雛形の作成。bundlerを使う。

  1. rspecでテストするつもりなので、-tオプションを付けてテストの雛形も同時に作成
  2. gemspecを修正して、テストが通るように修正する
  • 雛形ではshouldが使われているが、rspec3系では非推奨
## 雛形作成
$ bundle gem facemock -t
$ cd facemock

## gemspec修正
$ vi facemock.gemspec
$ git diff facemock.gemspec
+  spec.email         = ["ogawattim@gmail.com"]
+  spec.description   = %q{This is facebook mock application for fb_graph.}
+  spec.summary       = %q{This is facebook mock application for fb_graph.}
$ bundle install

## テスト実行・修正
$ rspec 

Facemock
  should have a version number
  should do something useful (FAILED - 1)

Failures:

  1) Facemock should do something useful
     Failure/Error: false.should be_true
       expected false to respond to `true?`
     # ./spec/facemock_spec.rb:9:in `block (2 levels) in <top (required)>'
...(以下略)...

## 生成されたテストの雛形facemock_spec.rbに失敗するテストが含まれる
$ vi spec/facemock_spec.rb  # 不要なテストを消しておく
$ cat spec/facemock_spec.rb
require 'spec_helper'

describe Facemock do
  it 'should have a version number' do
    Facemock::VERSION.should_not be_nil
  end
end

$ rspec

Facemock
  should have a version number

Deprecation Warnings:

Using `should_not` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from .../gem/facemock/spec/facemock_spec.rb:5:in `block (2 levels) in <top (required)>'.
...(以下略)...

## rspec3系ではshouldは非推奨なのでwarningが出る
$ vi spec/facemock_spec.rb
$ cat spec/facemock_spec.rb
require 'spec_helper'

describe Facemock do
  it 'should have a version number' do
    expect(Facemock::VERSION).not_to be_nil
  end
end

$ rspec

Facemock
  should have a version number

Finished in 0.00141 seconds (files took 0.06492 seconds to load)

First commit & push

First Commitして、先ほど作ったリポジトリにpushする。

  • bundlerで作成したgemの雛形では既にgit initされてる。
  • remote追加してpushする
## 変更点確認
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   .gitignore
#	new file:   .rspec
#	new file:   .travis.yml
#	new file:   Gemfile
#	new file:   LICENSE.txt
#	new file:   README.md
#	new file:   Rakefile
#	new file:   lib/facemock.rb
#	new file:   lib/facemock/version.rb
#	new file:   spec/spec_helper.rb
#	new file:   spec/facemock_spec.rb
#	new file:   facemock.gemspec
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   spec/facemock_spec.rb
#	modified:   facemock.gemspec
#
$ git diff (省略)

## First Commit
$ git add .
$ git commit
 12 files changed, 119 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .rspec
 create mode 100644 .travis.yml
 create mode 100644 Gemfile
 create mode 100644 LICENSE.txt
 create mode 100644 README.md
 create mode 100644 Rakefile
 create mode 100644 lib/facemock.rb
 create mode 100644 lib/facemock/version.rb
 create mode 100644 spec/spec_helper.rb
 create mode 100644 spec/facemock_spec.rb
 create mode 100644 facemock.gemspec

## Remote追加 & push
$ git remote add origin git@github.com:ogawatti/facemock.git

$ git push origin master
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (20/20), 2.85 KiB, done.
Total 20 (delta 2), reused 0 (delta 0)
To git@github.com:ogawatti/facemock.git
 * [new branch]      master -> master

これ以降にやったことはFacebookとの通信をmockするgemを作ってみたを参照。

参考

6
7
0

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
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?