Update rspec
This commit is contained in:
parent
f295e6ce80
commit
09faf06abb
|
@ -1,80 +0,0 @@
|
|||
---
|
||||
title: Rspec-rails
|
||||
layout: default
|
||||
---
|
||||
|
||||
### Require
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
### Controller tests
|
||||
|
||||
# spec/controllers/*
|
||||
describe ItemsController do
|
||||
it "works" do
|
||||
get :index
|
||||
expect(response).to be_success
|
||||
expect(response.status).to eq(200)
|
||||
expect(response).to render_template("index")
|
||||
end
|
||||
|
||||
it "loads all of the posts into @posts" do
|
||||
post1, post2 = Post.create!, Post.create!
|
||||
get :index
|
||||
|
||||
expect(assigns(:posts)).to match_array([post1, post2])
|
||||
end
|
||||
end
|
||||
|
||||
### Request specs
|
||||
|
||||
# spec/features/*
|
||||
describe "Foo tests", type: :request do
|
||||
include RequestHelpers
|
||||
|
||||
it "should work" do
|
||||
visit "/"
|
||||
expect(page).to have_content "Hello"
|
||||
expect(page).to have_selector "h1", text: "Welcome"
|
||||
end
|
||||
end
|
||||
|
||||
### View specs
|
||||
|
||||
# spec/views/*
|
||||
it "renders _event partial for each event" do
|
||||
assign(:events, [stub_model(Event), stub_model(Event)])
|
||||
render
|
||||
expect(view).to render_template(:partial => "_event", :count => 2)
|
||||
end
|
||||
|
||||
### Routes
|
||||
|
||||
# spec/routes/*
|
||||
describe "routing to profiles" do
|
||||
it "routes /profile/:username to profile#show for username" do
|
||||
expect(get: "/profiles/jsmith").to route_to(
|
||||
:controller => "profiles",
|
||||
:action => "show",
|
||||
:username => "jsmith"
|
||||
)
|
||||
end
|
||||
|
||||
it "does not expose a list of profiles" do
|
||||
expect(:get => "/profiles").not_to be_routable
|
||||
end
|
||||
end
|
||||
|
||||
### Helpers
|
||||
|
||||
# spec/helpers/*
|
||||
describe EventsHelper do
|
||||
describe "#link_to_event" do
|
||||
it "displays the title, and formatted date" do
|
||||
event = Event.new("Ruby Kaigi", Date.new(2010, 8, 27))
|
||||
# helper is an instance of ActionView::Base configured with the
|
||||
# EventsHelper and all of Rails' built-in helpers
|
||||
expect(helper.link_to_event).to match /Ruby Kaigi, 27 Aug, 2010/
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,17 @@ title: Rspec-rails controllers
|
|||
layout: default
|
||||
---
|
||||
|
||||
### Spec tasks
|
||||
|
||||
rake spec:controllers
|
||||
rake spec:helpers
|
||||
rake spec:lib
|
||||
rake spec:mailers
|
||||
rake spec:models
|
||||
rake spec:requests
|
||||
rake spec:routing
|
||||
rake spec:views
|
||||
|
||||
### Models
|
||||
|
||||
```rb
|
||||
|
|
18
rspec.md
18
rspec.md
|
@ -12,18 +12,6 @@ layout: default
|
|||
rake spec/models/mymodel_spec.rb
|
||||
rake spec/models/mymodel_spec.rb:27
|
||||
|
||||
### Other spec tasks
|
||||
|
||||
rake spec:controllers
|
||||
rake spec:helpers
|
||||
rake spec:lib
|
||||
rake spec:mailers
|
||||
rake spec:models
|
||||
rake spec:requests
|
||||
rake spec:routing
|
||||
rake spec:views
|
||||
|
||||
|
||||
### Spec helpers
|
||||
|
||||
module UserSpecHelper
|
||||
|
@ -149,3 +137,9 @@ expect { thing.destroy }.to change(Thing, :count).by(-1)
|
|||
expect(double).to receive(:msg).at_most(n).times
|
||||
expect(double).to receive(:msg).any_number_of_times
|
||||
|
||||
## Subjects
|
||||
|
||||
describe CheckingAccount, "with a non-zero balance" do
|
||||
subject(:account) { CheckingAccount.new }
|
||||
it { is_expected.not_to be_overdrawn }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue