<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by JerryNil on Medium]]></title>
        <description><![CDATA[Stories by JerryNil on Medium]]></description>
        <link>https://medium.com/@JerryNil?source=rss-afc0030f71ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kxp1MSIx65rM47UhQSXqkw.jpeg</url>
            <title>Stories by JerryNil on Medium</title>
            <link>https://medium.com/@JerryNil?source=rss-afc0030f71ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:31:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JerryNil/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[極簡料理]]></title>
            <link>https://medium.com/@JerryNil/%E6%A5%B5%E7%B0%A1%E6%96%99%E7%90%86-495d756b984c?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/495d756b984c</guid>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Tue, 08 Feb 2022 13:41:48 GMT</pubDate>
            <atom:updated>2022-02-08T13:41:48.718Z</atom:updated>
            <content:encoded><![CDATA[<p>極簡料理</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=495d756b984c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gfdgfdgdf]]></title>
            <link>https://medium.com/@JerryNil/gfdgfdgdf-c9c30fbf2660?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9c30fbf2660</guid>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Sun, 08 Aug 2021 03:37:26 GMT</pubDate>
            <atom:updated>2021-08-08T03:37:26.719Z</atom:updated>
            <content:encoded><![CDATA[<p>gfdgfdgdfgfdgdfgdfgdfgfdggfd</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9c30fbf2660" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hatch deploy]]></title>
            <link>https://medium.com/jerrynils-coding-diary/hatch-deploy-639786f05c63?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/639786f05c63</guid>
            <category><![CDATA[hatch]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Sat, 07 Oct 2017 04:22:28 GMT</pubDate>
            <atom:updated>2017-10-07T06:35:14.575Z</atom:updated>
            <content:encoded><![CDATA[<p>Hatch deploy</p><pre>ssh root@ip</pre><pre>輸入 mkdir -p /root/.ssh.............(如下方)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0pvO2xBUF2kBggDmlykjw.png" /></figure><p>登入</p><pre>ssh deploy@ip</pre><p>run the console with:</p><pre>cd my-app/current</pre><pre>bundle exec rails console</pre><p>import rake:</p><pre>cd my-app/current</pre><pre>bundle exec rake import:categories</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=639786f05c63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/hatch-deploy-639786f05c63">Hatch deploy</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rspec -6 撰寫 Routing 測試]]></title>
            <link>https://medium.com/jerrynils-coding-diary/rspec-6-%E6%92%B0%E5%AF%AB-routing-%E6%B8%AC%E8%A9%A6-f4718ea2cd8f?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4718ea2cd8f</guid>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[motion-express]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Tue, 26 Sep 2017 07:59:11 GMT</pubDate>
            <atom:updated>2017-09-26T08:26:36.579Z</atom:updated>
            <content:encoded><![CDATA[<p>首先在config/routes.rb檔案中新增root和一個自訂的action。</p><pre>resources :posts do<br>  resources :comments<br>end</pre><pre> root &quot;posts#index&quot;</pre><p>接下來到app/controllers/posts_controller.rb當中建立該action。</p><pre>def last_post<br>  @post = Post.last<br>end</pre><p>接下來即可撰寫測試！</p><p>spec/routes/posts_spec.rb</p><pre>require &#39;rails_helper&#39;</pre><pre>RSpec.describe &quot;posts&quot;, :type =&gt; :routing do<br>  it &quot;#index&quot; do<br>    expect(:get =&gt; &quot;/posts&quot;).to route_to(&quot;posts#index&quot;)<br>      # :controller =&gt; &quot;posts&quot;,<br>      # :action =&gt; &quot;index&quot;<br>      # )<br>  end</pre><pre>  it &quot;#show&quot; do<br>    expect(:get =&gt; &quot;/posts/1&quot;).to route_to(<br>      :controller =&gt; &quot;posts&quot;,<br>      :action =&gt; &quot;show&quot;,<br>      :id =&gt; &quot;1&quot;<br>      )<br>  end</pre><pre>  it &quot;#create&quot; do<br>    expect(:post =&gt; &quot;/posts&quot;).to route_to(<br>      :controller =&gt; &quot;posts&quot;,<br>      :action =&gt; &quot;create&quot;<br>      )<br>  end</pre><pre>  it &quot;#last_post&quot; do<br>    expect(:get =&gt; &quot;/posts/last_post&quot;).to route_to(<br>      :controller =&gt; &quot;posts&quot;,<br>      :action =&gt; &quot;last_post&quot;<br>      )<br>  end</pre><pre>  it &quot;root&quot; do<br>    expect(:get =&gt; &quot;/&quot;).to route_to(<br>      :controller =&gt; &quot;posts&quot;,<br>      :action =&gt; &quot;index&quot;<br>      )<br>  end<br>end</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4718ea2cd8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/rspec-6-%E6%92%B0%E5%AF%AB-routing-%E6%B8%AC%E8%A9%A6-f4718ea2cd8f">Rspec -6 撰寫 Routing 測試</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rspec -5 撰寫 model 測試]]></title>
            <link>https://medium.com/jerrynils-coding-diary/rspec-5-%E6%92%B0%E5%AF%AB-model-%E6%B8%AC%E8%A9%A6-b9360f4d2269?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9360f4d2269</guid>
            <category><![CDATA[motion-express]]></category>
            <category><![CDATA[rspec]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Mon, 25 Sep 2017 13:06:58 GMT</pubDate>
            <atom:updated>2017-09-26T07:58:06.911Z</atom:updated>
            <content:encoded><![CDATA[<p>由於 post.rb 裡有這一行：</p><pre>validates :title, presence: true</pre><p>所以 create 空的 post 會噴錯誤</p><p>建立另一個model與post產生關連。</p><pre>rails g model comment content:text post_id:integer</pre><pre>rake db:migrate</pre><p>在app/models/post.rb撰寫新的code。</p><pre>class Post &lt; ActiveRecord::Base<br>  validates :title, :presence =&gt; true<br>  has_many :comments</pre><pre>  def self.no_content<br>    where(:content =&gt; nil)<br>  end</pre><pre>  def abstract<br>    self.content[0..20]<br>  end<br>end</pre><p>在app/models/comment.rb當中建立關連。</p><pre>class Comment &lt; ActiveRecord::Base<br>  belongs_to :post<br>end</pre><p>接著在原本的model測試檔案內，新增測試。</p><p>spec/models/post_spec.rb</p><pre>it &quot;validates title&quot; do<br>    <strong>#create 兩個 post，一個有 title，一個沒 title，<br>     有 title 會過，沒 title 不會過</strong><br>    <br>    expect(Post.new).not_to be_valid<br>    expect(Post.create(title: &quot;title&quot;)).to be_valid<br>  end</pre><pre>it &quot;.no_content&quot; do<br>    <strong>#create 兩個 post，一個有 content，一個沒 content，<br>    呼叫 .no_content，會包含沒 content，不會包含有 content </strong></pre><pre>    post_with_content = Post.create(title: &quot;title&quot;, content: &quot;content&quot;)<br>    post_without_content = Post.create(title: &quot;title&quot;, content: nil)<br>    expect(Post.no_content).to include(post_without_content)<br>    expect(Post.no_content).not_to include(post_with_content)<br>  end</pre><pre>  it &quot;#abstract&quot; do<br>    <strong>#create 有 title 的 post，測試呼叫 #abstract 後是否有 20個字</strong><br>    <br>    post = Post.create(title: &quot;title&quot;, content: &quot;abcdefghijklmnopqrstuv&quot;)<br>    expect(post.abstract.size).to eq(20)<br>  end</pre><pre>  it &quot;has_many comments&quot; do<br>    <strong>#create 一個 post, 一個 comment，測試 post.comment 是否包含 comment</strong><br>    <br>    post = Post.create(title: &quot;title&quot;, content: &quot;content&quot;)<br>    comment = Comment.create(content: &quot;content&quot;, post_id: post.id)<br>    expect(post.comments).to include(comment)<br>  end</pre><p>進行測試：</p><pre>$ rspec spec/models</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9360f4d2269" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/rspec-5-%E6%92%B0%E5%AF%AB-model-%E6%B8%AC%E8%A9%A6-b9360f4d2269">Rspec -5 撰寫 model 測試</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rspec -4 撰寫 view 測試]]></title>
            <link>https://medium.com/jerrynils-coding-diary/rspec-4-%E6%92%B0%E5%AF%AB-view-%E6%B8%AC%E8%A9%A6-24c7c18fe92c?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/24c7c18fe92c</guid>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[motion-express]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Mon, 25 Sep 2017 05:30:00 GMT</pubDate>
            <atom:updated>2017-09-25T09:25:14.784Z</atom:updated>
            <content:encoded><![CDATA[<p>新增 spec/views/posts/index_spec.rb</p><p>RSpec 預設是 unit test，只會在 view 裡面做測試，不會跟 controller 要資料</p><h3>測試 index 頁面 ( 測是否有 render )</h3><pre>require &quot;rails_helper&quot;</pre><pre>RSpec.describe &quot;posts/index.html.erb&quot;, type: :view do<br># describe 後面接的是路徑</pre><pre>  it &quot;can render&quot; do<br>    @post = Post.create(title: &quot;Big Title&quot;, content: &quot;content_1&quot;)<br>    @posts = Array.new(2, @post)<br>    render<br>    expect(rendered).to include(&quot;Title&quot;)<br>    expect(rendered).to include(&quot;Big Title&quot;)<br>    expect(rendered).to include(&quot;content_1&quot;)<br>  end<br>end</pre><p>rspec 的測試範圍僅限於 ruby code，而且是測 <strong>render 後該出現的是否有出現</strong>，不測 css 或 javascript</p><h3>describe 後面接的是路徑</h3><h3>測試 edit 頁面 (測是否有 render partial，是否有 link)</h3><p>新增 spec/views/posts/edit_spec.rb</p><pre>require &quot;rails_helper&quot;</pre><pre>RSpec.describe &quot;posts/edit.html.erb&quot;, type: :view do<br>  before(:each) do<br>    @post = Post.create(title: &quot;Big Title&quot;, content: &quot;conten_1&quot;)<br>  end</pre><pre>it &quot;render partial&quot; do<br>    render<br>    expect(response).to render_template(partial: &quot;posts/_form&quot; )<br>  end</pre><pre>it &quot;has link&quot; do<br>    render<br>    expect(rendered).to include(&quot;Show&quot;)<br>    expect(rendered).to include(&quot;Back&quot;)<br>  end<br>end</pre><h3>測試 show 頁面 (測是否有 render content，以及測沒有 content 的反應)</h3><pre>require &quot;rails_helper&quot;</pre><pre>RSpec.describe &quot;posts/show.html.erb&quot;, type: :view do<br>  before(:each) do<br>    @post = Post.create(title: &quot;Big Title&quot;, content: nil)<br>  end</pre><pre>it &quot;renders &#39;No Content&#39; when @post has no content&quot; do<br>    render<br>    expect(rendered).to include(&quot;No Content&quot;)<br>  end</pre><pre>it &quot;renders content when @post has content&quot; do<br>    allow(view).to receive(:render_content).and_return(&quot;Stub Content&quot;)<br>    @post.content = &quot;I love rails&quot;<br>    render<br>    expect(rendered).not_to include(&quot;I love rails&quot;)<br>    expect(rendered).not_to include(&quot;No Content&quot;)<br>    expect(rendered).to include(&quot;Stub Content&quot;)<br>  end<br>end</pre><h3>測試 index.json.jbuilder (寫在 index_spec.rb 裡面)</h3><pre>RSpec.describe &quot;posts/index.json.jbuilder&quot;, type: :view do<br>  it &quot;contains data&quot; do<br>    @post = Post.create(title: &quot;Big Title&quot;, content: &quot;content_1&quot;)<br>    @posts = Array.new(2, @post)<br>    render<br>    expect(rendered).to include(&quot;id&quot;)<br>    expect(rendered).to include(&quot;title&quot;)<br>    expect(rendered).to include(&quot;content&quot;)<br>  end<br>end</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24c7c18fe92c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/rspec-4-%E6%92%B0%E5%AF%AB-view-%E6%B8%AC%E8%A9%A6-24c7c18fe92c">Rspec -4 撰寫 view 測試</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rspec -3 撰寫controller測試]]></title>
            <link>https://medium.com/jerrynils-coding-diary/rspec-3-%E6%92%B0%E5%AF%ABcontroller%E6%B8%AC%E8%A9%A6-bd9c73203050?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd9c73203050</guid>
            <category><![CDATA[motion-express]]></category>
            <category><![CDATA[rspec]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Sat, 23 Sep 2017 12:54:05 GMT</pubDate>
            <atom:updated>2017-09-25T04:05:04.387Z</atom:updated>
            <content:encoded><![CDATA[<p>新增 spec/controller/posts.spec.rb，編輯：</p><pre>require &quot;rails_helper<br>#rspec 相關的設定檔</pre><pre>RSpec.describe PostController, type: :controller do<br>  <br>end</pre><p>在 block 裡面新增：</p><pre>it &quot;#index&quot; do<br>end</pre><p>#index 表示 instance method</p><p>.index 表示 class method</p><blockquote>想像一個 class是一個大團體，裡頭的每一個人都是一個 instance，假如我們要對整個團體下命令，就是在執行 class method；反之假如是對其中一個人下命令，則就是執行 instance method。</blockquote><h3>測試 index 方法</h3><pre>RSpec.describe PostsController, type: :controller do<br>  it &#39;#index&#39; do<br>    get :index<br>    expect(response).to have_http_status(200)<br>    expect(response).to render_template(:index)<br>  end<br>end</pre><p>跳出：</p><pre>assert_template has been extracted to a gem. To continue using it,<br>add gem &#39;rails-controller-testing&#39; to your Gemfile.</pre><p>安裝:</p><pre>gem &#39;rails-controller-testing&#39;</pre><h3>測試 new 方法</h3><pre>it &#39;#new&#39; do<br>  get :new<br>  expect(response).to have_http_status(200)<br>  expect(response).to render_template(:new)<br>end</pre><h3>測試 edit 方法之前</h3><p>edit 必須先要有檔案，所以先用 before_action 產生兩個檔案</p><pre>before(:all) do<br>  @post_1 = Post.create(title:title_1, content:content_1)<br>  @post_2 = Post.create(title:title_2, content:content_2)<br>end</pre><h3>測試 edit 方法</h3><p>HTTP request methods will accept only the following keyword arguments params, headers, env, xhr</p><pre>it &#39;#edit&#39; do<br>  get :edit, params: {id: @post_1[:id]}<br>  expect(response).to have_http_status(200)<br>  expect(response).to render_template(:edit)<br>end</pre><h3>測試 create 方法</h3><p>用 describe 來包 describe，因為有不同的 action 需要被執行</p><pre>describe &#39;#create&#39; do<br>  before(:all) do<br>    @post_params = {title:&quot;title&quot;, content:&quot;content&quot;}<br>  end<br>    <br>  it &quot;creates rocord&quot; do<br>    expect { post :create, params:{post: @post_params} }.to  change{Post.all.size}.by(1)<br>  end<br>    <br>  it &quot;redirect on success&quot; do<br>    post :create, params:{post: @post_params}</pre><pre>    expect(response).to have_http_status(302)<br>    #正面測試</pre><pre>    expect(response).not_to have_http_status(200)<br>    #反面測試</pre><pre>    expect(response).to redirect_to post_path(Post.last)<br>    #redirect 測試</pre><pre>  end</pre><pre>  it &quot;render :new on fail&quot; do<br>    allow_any_instance_of(Post).to receive(:save).and_return(false)<br>    post :create, params: {post: @post_params}<br>      <br>    expect(response).to have_http_status(200)<br>    #ok</pre><pre>    expect(response).not_to have_http_status(302)<br>    #沒有 redirect</pre><pre>    expect(response).to render_template(:new)<br>  end<br>end</pre><h3>測試 update 方法</h3><p>複製 create 的測試方法，改名 update，但是 update 要帶入 id</p><p>在 it 前面加 x 可以讓這個測試 pending</p><pre>describe &#39;#update&#39; do</pre><pre>  before(:all) do<br>    @post_params = {title:&quot;title-3&quot;, content:&quot;content-3&quot;}<br>  end</pre><pre>  it &quot;changes rocord&quot; do<br>    post :update, params:{post: @post_params, id: @post_2[:id]}<br>    expect(Post.find(@post_2[:id]).title).to eq(&quot;title-3&quot;)<br>  end</pre><pre>  it &quot;redirect on success&quot; do<br>    post :update, params:{post: @post_params, id: @post_2[:id]}<br>    expect(response).to have_http_status(302)<br>    expect(response).not_to have_http_status(200)<br>    expect(response).to redirect_to post_path(id: @post_2[:id] )<br>  end</pre><pre>  it &quot;render :edit on fail&quot; do<br>    allow_any_instance_of(Post).to receive(:update).and_return(false)<br>      post :update, params: {post: @post_params, id: @post_2[:id]}<br>      expect(response).not_to have_http_status(302)<br>      expect(response).to render_template(:edit)<br>    end</pre><pre>end</pre><p><a href="https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81">HTTP状态码</a></p><p>http 狀態碼</p><p>2XX 成功</p><p>3XX 重新轉向</p><h3>測試 destroy 方法</h3><pre>describe &quot;#destroy&quot; do<br>  <br>  before(:each) do<br>    @post_3 = @post_2 || Post.create(post_params: {title: &quot;title-3&quot;, content: &quot;content-3&quot;})<br>  end</pre><pre>  it &quot;deletes record&quot; do<br>    expect{post :destroy, method: :delete, params: {id: @post_2[:id]}}.to change{Post.all.size}.by(-1)<br>  end</pre><pre>  it &quot;redirect to :index on success&quot; do<br>    post :destroy, method: :delete, params: {id: @post_2[:id]}<br>    expect(response).to redirect_to posts_path<br>    expect(response).to have_http_status(302)<br>  end<br>end</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd9c73203050" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/rspec-3-%E6%92%B0%E5%AF%ABcontroller%E6%B8%AC%E8%A9%A6-bd9c73203050">Rspec -3 撰寫controller測試</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rspec -2 安裝 RSpec 至 Rails]]></title>
            <link>https://medium.com/jerrynils-coding-diary/rspect-2-%E5%AE%89%E8%A3%9D-rspec-%E8%87%B3-rails-396c4b7ec577?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/396c4b7ec577</guid>
            <category><![CDATA[motion-express]]></category>
            <category><![CDATA[rspec]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Sat, 23 Sep 2017 10:38:32 GMT</pubDate>
            <atom:updated>2017-09-23T10:38:47.330Z</atom:updated>
            <content:encoded><![CDATA[<p>rails new demo-app</p><p>把 rspec-rails 加到 gemfile 裡面(development and test)</p><pre>rails g rspect:install</pre><p>到 application.rb，拿掉 scaffold 自動產生 rspect 的功能</p><pre>config.generators do |g|<br>  g.controller_specs false<br>  g.view_specs false<br>  g.helper_specs false<br>  g.routing_specs false<br>  g.request_specs false<br>end</pre><p>產生 scaffold</p><pre>rails g scaffold Post title:string content:text --no-assets</pre><pre>rails db:migrate</pre><p>如果 post model 已經存在：</p><pre>rails db:drop</pre><pre>rails db:create</pre><pre>rails db:migrate</pre><p>post_specs.rb，測試 Post model 能不能被存取</p><pre>RSpec.describe Post, type: :model do<br>  it &quot;is accessible&quot; do<br>    post = Post.create!<br>    expect(post).to eq(Post.last)<br>  end<br>end</pre><p>跑 rspec</p><p>post_specs.rb，測試 Post 欄位有沒有包含 id, title, content</p><pre>it &quot;has title and content columns&quot; do<br>  columns = Post.column_names<br>  # =&gt; [&quot;id&quot;, &quot;title&quot;, &quot;content&quot;]</pre><pre>  expect(columns).to include(&quot;id&quot;)<br>  expect(columns).to include(&quot;title&quot;)<br>  expect(columns).to include(&quot;content&quot;)<br>end</pre><p>測試要寫一個正面一個反面</p><pre>expect(columns).not_to include(user_id) </pre><p>跑 rspec</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=396c4b7ec577" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/rspect-2-%E5%AE%89%E8%A3%9D-rspec-%E8%87%B3-rails-396c4b7ec577">Rspec -2 安裝 RSpec 至 Rails</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RSpec -1 基本用法]]></title>
            <link>https://medium.com/jerrynils-coding-diary/rspec-1-%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95-846f51a7adb?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/846f51a7adb</guid>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[motion-express]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Tue, 19 Sep 2017 08:25:32 GMT</pubDate>
            <atom:updated>2017-09-23T08:31:57.789Z</atom:updated>
            <content:encoded><![CDATA[<pre>gem install rspec</pre><pre>subl basic_spec.rb</pre><p>編輯 basic_spec.rb</p><pre>require &#39;rspec&#39;</pre><pre>describe &#39;math&#39; do<br>  it &#39;do basic math&#39; do<br>     expect(1+1).to eq(2)<br>  end<br>end</pre><p>執行：</p><pre>rspec basic_spec.rb  </pre><p>得到的結果：</p><pre>Finished in 0.00398 seconds (files took 0.1625 seconds to load)<br><strong>1 example, 0 failures</strong></pre><p>在 basic_spec.rb 裡再加一行</p><pre>expect(1+1).to eq(3)</pre><p>跑 rspec 會：</p><pre>Failures:</pre><pre>1) math do basic math<br>     Failure/Error: expect(1+1).to eq(3)</pre><pre>expected: 3<br>     got: 2</pre><pre>(compared using ==)<br>     # ./basic_spec.rb:6:in `block (2 levels) in &lt;top (required)&gt;&#39;</pre><pre>Finished in 0.02862 seconds (files took 0.11824 seconds to load)<br><strong>1 example, 1 failure</strong></pre><p>salary_divider</p><pre>require &#39;rspec&#39;</pre><pre>class Divider<br>  def divide_salary(salary)<br>    case salary<br>    when 0..300000<br>      p&quot;年收入30萬以下&quot;<br>    when 300001..600000<br>      p&quot;年收入30~60萬之間&quot;<br>    when 600001..900000<br>      p&quot;年收入60~90萬之間&quot;<br>    else<br>      p&quot;年收入90萬以上&quot;<br>    end<br>  end<br>end</pre><pre>describe &#39;Divider&#39; do<br>  it &#39;successfully devides people based on salary&#39; do<br>    expect(Divider.new.divide_salary(250000)).to eq(&quot;年收入30萬以下&quot;)<br>    expect(Divider.new.divide_salary(350000)).to eq(&quot;年收入30~60萬之間&quot;)<br>    expect(Divider.new.divide_salary(650000)).to eq(&quot;年收入60~90萬之間&quot;)<br>    expect(Divider.new.divide_salary(950000)).to eq(&quot;年收入90萬以上&quot;)<br>  end<br>end</pre><p>測試網站連線是否正常</p><p>gem install httpclient</p><pre>require &#39;rspec&#39;<br>require &#39;httpclient&#39;</pre><pre>describe &quot;connections&quot; do<br>  it &quot;are stable&quot; do<br>    expect(HTTPClient.new.get(&quot;<a href="https://medium.com/jerrynils-coding-diary">https://medium.com/jerrynils-coding-diary</a>&quot;).status).to eq(200)<br>    expect(HTTPClient.new.get(&quot;<a href="http://installrails.com/">http://installrails.com/</a>&quot;).status).to eq(200)<br>    expect(HTTPClient.new.get(&quot;<a href="http://installrails.com/">http://installrails.com/</a>&quot;)<strong>.body).to include</strong>(&quot;InstallRails.com is the easier way to install Rails on your computer&quot;)<br>  end<br>end</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=846f51a7adb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jerrynils-coding-diary/rspec-1-%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95-846f51a7adb">RSpec -1 基本用法</a> was originally published in <a href="https://medium.com/jerrynils-coding-diary">JerryNil’s Coding Diary</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kevin 講長進]]></title>
            <link>https://medium.com/@JerryNil/%E7%A5%9E%E6%9C%83%E9%A4%8A%E6%88%91%E7%9A%84-6634b6c5747d?source=rss-afc0030f71ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6634b6c5747d</guid>
            <category><![CDATA[peach]]></category>
            <category><![CDATA[sunday]]></category>
            <dc:creator><![CDATA[JerryNil]]></dc:creator>
            <pubDate>Sun, 17 Sep 2017 02:52:05 GMT</pubDate>
            <atom:updated>2017-09-17T03:01:17.838Z</atom:updated>
            <content:encoded><![CDATA[<h3>聖靈更新：更年輕沒傳統</h3><blockquote>「第二次有聲音向他說：「神所潔淨的，你不可當作俗物。」 這樣一連三次，那物隨即收回天上去了。」使徒行傳‬ ‭10:15–16‬ ‭CUNP-神‬‬</blockquote><blockquote>「務要牧養在你們中間神的羣羊，按着神 旨意 照管他們；不是出於勉強，乃是出於甘心；也不是因為貪財，乃是出於樂意； 也不是轄制所託付你們的，乃是作羣羊的榜樣。 到了牧長顯現的時候，你們必得那永不衰殘的榮耀冠冕。」‭‭彼得前書‬ ‭5:2–4‬ ‭CUNP-神‬‬</blockquote><p>為了神哪裡都能去，跟為了神哪裡都不去，都是挑戰</p><p>神能塑造彼得，也能塑造我</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6634b6c5747d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>