Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Rspec3 #17

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/autodoc/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def self.render(*args)
new(*args).render
end

def initialize(context)
def initialize(context, example)
@context = context
@example = example
end

def pathname
@path ||= begin
payload = @context.example.file_path.gsub(%r<\./spec/requests/(.+)_spec\.rb>, '\1.md')
payload = @example.file_path.gsub(%r<\./spec/requests/(.+)_spec\.rb>, '\1.md')
Autodoc.configuration.pathname + payload
end
end
Expand Down Expand Up @@ -176,12 +177,12 @@ def description
if @context.respond_to?(:description)
@context.description.strip_heredoc
else
"#{@context.example.description.capitalize}."
"#{@example.description.capitalize}."
end
end

def path
@context.example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
@example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
end

def parameters_section
Expand Down
4 changes: 2 additions & 2 deletions lib/autodoc/documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def initialize
@table = Hash.new {|table, key| table[key] = [] }
end

def append(context)
document = Autodoc::Document.new(context.clone)
def append(context, example)
document = Autodoc::Document.new(context.clone, example.clone)
@table[document.pathname] << document
end

Expand Down
7 changes: 6 additions & 1 deletion lib/autodoc/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require "rspec"

RSpec.configuration.after(:each, autodoc: true) do
Autodoc.documents.append(self)
example = if RSpec.respond_to?(:current_example) #RSpec 3~
RSpec.current_example
else
self.example
end
Autodoc.documents.append(self, example)
end

RSpec.configuration.after(:suite) do
Expand Down
2 changes: 1 addition & 1 deletion spec/autodoc/documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Autodoc::Documents do
describe "#render_toc" do
before do
documents.append(context)
documents.append(context, example)
end

let(:documents) do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/entries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end

describe "GET /entries" do
context "with Rack::Test", :autodoc do
context "with Rack::Test", autodoc: true do
it "returns entries" do
get "/entries", params, env
last_response.status.should == 200
Expand Down
11 changes: 8 additions & 3 deletions spec/requests/recipes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

describe "Recipes" do
describe "Recipes", type: :request do
let(:env) do
{ "ACCEPT" => "application/json", "CONTENT_TYPE" => "application/json" }
end
Expand All @@ -9,18 +9,23 @@
{}
end


describe "GET /recipes/:id" do
let(:recipe) do
Recipe.create(name: "test", type: 2)
end

context "with valid condition (using Rack::Test)", :autodoc do
context "with valid condition (using Rack::Test)", autodoc: true do
before do
env["Content-Type"] = "application/json"
end

include Rack::Test::Methods

let(:app) do
Dummy::Application
end

it "returns the recipe" do
get "/recipes/#{recipe.id}", params, env
last_response.status.should == 200
Expand Down Expand Up @@ -67,7 +72,7 @@
end
end

context "with valid condition", :autodoc do
context "with valid condition", autodoc: true do
let(:description) do
<<-EOS
Creates
Expand Down
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../spec/dummy/config/environment", __FILE__)
require "rspec/rails"
require "rspec/autorun"

Autodoc.configuration.toc = true
Autodoc.configuration.path = "spec/dummy/doc"
Expand All @@ -16,6 +15,4 @@
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false

config.treat_symbols_as_metadata_keys_with_true_values = true
end