Skip to content

Instantly share code, notes, and snippets.

module Bar
def self.included(clazz)
clazz.extend Baz
end
module Baz
def bar
puts 'bar'
end
end
$ rspec spec/requests/homepage_spec.rb
F
Failures:
1) The homepage displays recent posts from Hacker News
Failure/Error: visit '/'
NoMethodError:
undefined method `recent' for HN::Post:Class
# ./app/models/post.rb:3:in `recent'
require 'spec_helper'
describe 'The homepage', :vcr do
before do
visit '/'
end
it 'displays recent posts from Hacker News' do
hacker_news_links = all '#hn .post a'
hacker_news_links.should_not be_empty
Scenario Outline: Make an API request from a different domain
When I ask if a <http-method> request to <api-path> from a different domain is supported
Then I should receive a successful response
And the <http-method> request should be allowed
Scenarios: Available APIs
| http-method | api-path |
| GET | /api/v1/samples |
| GET | /api/v1/samples/1 |
| PUT | /api/v1/samples/1 |
$ curl \
--verbose \
--request OPTIONS \
http://localhost:3000/users/1.json \
--header 'Origin: http://server1.example.com' \
--header 'Access-Control-Request-Headers: Origin, Accept, Content-Type' \
--header 'Access-Control-Request-Method: PUT'
* About to connect() to localhost port 3000 (#0)
* Trying ::1... Connection refused
* Trying 127.0.0.1... connected
<script type="text/javascript">
function parseUser (json) {
var user = new User(json)
// do something with the user
}
</script>
<script type="text/javascript"
src="http://server2.example.com/users/1.js?callback=parseUser">
In order to reference published articles in other applications
As an API client
I want to be able to request articles via a JSON API
$ cucumber features/api/v1/articles.feature
Using the default profile...
....
1 scenario (1 passed)
4 steps (4 passed)
$ rspec spec/models/article_spec.rb
.
Finished in 0.10455 seconds
1 example, 0 failures
class Article < ActiveRecord::Base
def self.published
where :published => true
end
end