Update rspec
This commit is contained in:
parent
743006eaa7
commit
f0ec286024
|
@ -1,49 +0,0 @@
|
||||||
---
|
|
||||||
title: GitHub 2FA
|
|
||||||
---
|
|
||||||
|
|
||||||
### Prepare your phone
|
|
||||||
Install [Google Authenticator](https://en.wikipedia.org/wiki/Google_Authenticator). Works for iOS and Android.
|
|
||||||
|
|
||||||
### Enable 2FA
|
|
||||||
|
|
||||||
* Enable [2 factor authentication](https://github.com/settings/security) on the GitHub website (Settings → Security → Two Factor Authentication).
|
|
||||||
* Take a picture of the QR code using Google Authenticator.
|
|
||||||
|
|
||||||
### Enable password caching
|
|
||||||
On your computer, [enable caching your GitHub HTTPS credentials](https://help.github.com/articles/caching-your-github-password-in-git/). This allows you to store your 2FA token and not get asked for it everytime.
|
|
||||||
|
|
||||||
```
|
|
||||||
git config --global credential.helper osxkeychain # OSX
|
|
||||||
git config --global credential.helper cache # Linux
|
|
||||||
```
|
|
||||||
|
|
||||||
### Use HTTPS on your repos
|
|
||||||
If your git repos still use SSH (`git@github.com:user/repo.git`), change them to use HTTPS (`https://github.com/user/repo.git`). [Info here](https://help.github.com/articles/which-remote-url-should-i-use/#cloning-with-https-recommended).
|
|
||||||
|
|
||||||
```
|
|
||||||
cd project
|
|
||||||
vim .git/config
|
|
||||||
```
|
|
||||||
|
|
||||||
### Generate an API key
|
|
||||||
|
|
||||||
* [Generate an API key](https://github.com/settings/applications#personal-access-tokens) under "Personal Access Tokens". You'll use this as a password.
|
|
||||||
* Leave the scopes unchanged. (as long as there's *repo* + *public_repo*)
|
|
||||||
|
|
||||||
### Git push
|
|
||||||
Push a repo. You'll be asked for a password. Use the token for the password.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ git push
|
|
||||||
Username for 'https://github.com': rstacruz
|
|
||||||
Password for 'https://rstacruz@github.com':
|
|
||||||
```
|
|
||||||
|
|
||||||
### That's it!
|
|
||||||
|
|
||||||
Further reading:
|
|
||||||
|
|
||||||
* [Providing your 2FA Authentication Code](https://help.github.com/articles/providing-your-2fa-authentication-code/) (github.com)
|
|
||||||
* [Caching your GitHub password](https://help.github.com/articles/caching-your-github-password-in-git/) (github.com)
|
|
||||||
* [HTTPS remote URLs](https://help.github.com/articles/which-remote-url-should-i-use/) (github.com)
|
|
|
@ -1,22 +0,0 @@
|
||||||
---
|
|
||||||
title: Rspec-rails controllers
|
|
||||||
layout: default
|
|
||||||
---
|
|
||||||
|
|
||||||
```rb
|
|
||||||
describe MyController do
|
|
||||||
describe "POST update" do
|
|
||||||
it "works" do
|
|
||||||
post :update, { user: { name: "john" } }
|
|
||||||
|
|
||||||
controller
|
|
||||||
controller.send ...
|
|
||||||
|
|
||||||
response
|
|
||||||
expect(response).to be_success
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
expect(response).to render_template("index")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
```
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
---
|
||||||
|
title: Rspec-rails controllers
|
||||||
|
layout: default
|
||||||
|
---
|
||||||
|
|
||||||
|
### Models
|
||||||
|
|
||||||
|
```rb
|
||||||
|
# spec/models/*.rb
|
||||||
|
decribe MyModel do
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### Controllers
|
||||||
|
|
||||||
|
```rb
|
||||||
|
# spec/controllers/*.rb
|
||||||
|
describe MyController do
|
||||||
|
describe "POST update" do
|
||||||
|
it "works" do
|
||||||
|
post :update, { user: { name: "john" } }
|
||||||
|
|
||||||
|
controller
|
||||||
|
controller.send ...
|
||||||
|
|
||||||
|
response
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
expect(response).to render_template("index")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### Request
|
||||||
|
|
||||||
|
```js
|
||||||
|
# spec/requests/*.rb
|
||||||
|
describe "home page" do
|
||||||
|
it "displays the user's username after successful login" do
|
||||||
|
user = User.create!(:username => "jdoe", :password => "secret")
|
||||||
|
|
||||||
|
get "/login"
|
||||||
|
|
||||||
|
assert_select "form.login" do
|
||||||
|
assert_select "input[name=?]", "username"
|
||||||
|
assert_select "input[name=?]", "password"
|
||||||
|
assert_select "input[type=?]", "submit"
|
||||||
|
end
|
||||||
|
|
||||||
|
post "/login", username: "jdoe", password: "secret"
|
||||||
|
# capybara
|
||||||
|
expect(page).to have_selector(".header .username", :text => "jdoe")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### Routing
|
||||||
|
|
||||||
|
```rb
|
||||||
|
# spec/routing/*.rb
|
||||||
|
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
|
||||||
|
|
||||||
|
```rb
|
||||||
|
# spec/helpers/*.rb
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
### Matchers
|
||||||
|
|
||||||
|
```rb
|
||||||
|
be_a_new(Widget) # new_record?
|
||||||
|
render_template("new")
|
||||||
|
render_template(partial: 'form', locals: {...})
|
||||||
|
redirect_to(widgets_path)
|
||||||
|
route_to(..)
|
||||||
|
be_routable
|
||||||
|
have_http_status(500)
|
||||||
|
have_http_status(:created)
|
||||||
|
```
|
Loading…
Reference in New Issue