Skip to content

Commit 9803e1f

Browse files
committed
Remove deprecation warnings
1 parent b47795f commit 9803e1f

22 files changed

+202
-205
lines changed

Gemfile.lock

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PATH
66
i18n (>= 0.1.0)
77
json (>= 1.4.6)
88
mustache (>= 0.99.4)
9-
rspec (~> 2.99.0.rc1)
9+
rspec (~> 3.0.0.rc1)
1010

1111
GEM
1212
remote: http://rubygems.org/
@@ -80,17 +80,21 @@ GEM
8080
rack-test (0.6.2)
8181
rack (>= 1.0)
8282
rake (10.1.0)
83-
rspec (2.99.0.rc1)
84-
rspec-core (= 2.99.0.rc1)
85-
rspec-expectations (= 2.99.0.rc1)
86-
rspec-mocks (= 2.99.0.rc1)
87-
rspec-core (2.99.0.rc1)
88-
rspec-expectations (2.99.0.rc1)
89-
diff-lcs (>= 1.1.3, < 2.0)
83+
rspec (3.0.0.rc1)
84+
rspec-core (= 3.0.0.rc1)
85+
rspec-expectations (= 3.0.0.rc1)
86+
rspec-mocks (= 3.0.0.rc1)
87+
rspec-core (3.0.0.rc1)
88+
rspec-support (= 3.0.0.rc1)
89+
rspec-expectations (3.0.0.rc1)
90+
diff-lcs (>= 1.2.0, < 2.0)
91+
rspec-support (= 3.0.0.rc1)
9092
rspec-its (1.0.1)
9193
rspec-core (>= 2.99.0.beta1)
9294
rspec-expectations (>= 2.99.0.beta1)
93-
rspec-mocks (2.99.0.rc1)
95+
rspec-mocks (3.0.0.rc1)
96+
rspec-support (= 3.0.0.rc1)
97+
rspec-support (3.0.0.rc1)
9498
safe_yaml (0.9.7)
9599
sinatra (1.4.4)
96100
rack (~> 1.4)

lib/rspec_api_documentation/api_formatter.rb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,39 @@
22

33
module RspecApiDocumentation
44
class ApiFormatter < RSpec::Core::Formatters::BaseTextFormatter
5+
RSpec::Core::Formatters.register self, :example_passed, :example_failed, :stop
6+
57
def initialize(output)
68
super
79

810
output.puts "Generating API Docs"
911
end
1012

11-
def start(example_count)
13+
def start(notification)
1214
super
1315

1416
RspecApiDocumentation.documentations.each(&:clear_docs)
1517
end
1618

17-
def example_group_started(example_group)
19+
def example_group_started(notification)
1820
super
1921

20-
output.puts " #{example_group.description}"
22+
output.puts " #{@example_group.description}"
2123
end
2224

23-
def example_passed(example)
24-
super
25-
26-
output.puts " * #{example.description}"
25+
def example_passed(example_notification)
26+
output.puts " * #{example_notification.example.description}"
2727

2828
RspecApiDocumentation.documentations.each do |documentation|
29-
documentation.document_example(example)
29+
documentation.document_example(example_notification.example)
3030
end
3131
end
3232

33-
def example_failed(example)
34-
super
35-
36-
output.puts " ! #{example.description} (FAILED)"
33+
def example_failed(example_notification)
34+
output.puts " ! #{example_notification.example.description} (FAILED)"
3735
end
3836

3937
def stop
40-
super
41-
4238
RspecApiDocumentation.documentations.each(&:write)
4339
end
4440
end

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ module Endpoint
1212

1313
module ClassMethods
1414
def example_request(description, params = {}, &block)
15-
file_path = caller.first[0, caller.first =~ /:/]
16-
17-
location = caller.first[0, caller.first =~ /(:in|$)/]
18-
location = relative_path(location)
19-
20-
example description, :location => location, :file_path => file_path do
15+
example description do
2116
do_request(params)
2217
instance_eval &block if block_given?
2318
end

rspec_api_documentation.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414

1515
s.required_rubygems_version = ">= 1.3.6"
1616

17-
s.add_runtime_dependency "rspec", "~> 2.99.0.rc1"
17+
s.add_runtime_dependency "rspec", "~> 3.0.0.rc1"
1818
s.add_runtime_dependency "activesupport", ">= 3.0.0"
1919
s.add_runtime_dependency "i18n", ">= 0.1.0"
2020
s.add_runtime_dependency "mustache", ">= 0.99.4"

spec/api_documentation_spec.rb

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
test_file = configuration.docs_dir.join("test")
1616
FileUtils.mkdir_p configuration.docs_dir
1717
FileUtils.touch test_file
18-
FileUtils.stub(:cp_r)
18+
allow(FileUtils).to receive(:cp_r)
1919
subject.clear_docs
2020

21-
File.directory?(configuration.docs_dir).should be_truthy
22-
File.exists?(test_file).should be_falsey
21+
expect(File.directory?(configuration.docs_dir)).to be_truthy
22+
expect(File.exists?(test_file)).to be_falsey
2323
end
2424
end
2525

@@ -30,29 +30,29 @@
3030
let!(:wrapped_example) { RspecApiDocumentation::Example.new(example, configuration) }
3131

3232
before do
33-
RspecApiDocumentation::Example.stub(:new).and_return(wrapped_example)
33+
allow(RspecApiDocumentation::Example).to receive(:new).and_return(wrapped_example)
3434
end
3535

3636
it "should create a new wrapped example" do
37-
RspecApiDocumentation::Example.should_receive(:new).with(example, configuration).and_return(wrapped_example)
37+
expect(RspecApiDocumentation::Example).to receive(:new).with(example, configuration).and_return(wrapped_example)
3838
documentation.document_example(example)
3939
end
4040

4141
context "when the given example should be documented" do
42-
before { wrapped_example.stub(:should_document?).and_return(true) }
42+
before { allow(wrapped_example).to receive(:should_document?).and_return(true) }
4343

4444
it "should add the wrapped example to the index" do
4545
documentation.document_example(example)
46-
documentation.index.examples.should eq([wrapped_example])
46+
expect(documentation.index.examples).to eq([wrapped_example])
4747
end
4848
end
4949

5050
context "when the given example should not be documented" do
51-
before { wrapped_example.stub(:should_document?).and_return(false) }
51+
before { allow(wrapped_example).to receive(:should_document?).and_return(false) }
5252

5353
it "should not add the wrapped example to the index" do
5454
documentation.document_example(example)
55-
documentation.index.examples.should be_empty
55+
expect(documentation.index.examples).to be_empty
5656
end
5757
end
5858
end
@@ -68,8 +68,9 @@ class RspecApiDocumentation::Writers::TextileWriter; end
6868
end
6969

7070
it "should return the classes from format" do
71-
subject.writers.should == [RspecApiDocumentation::Writers::HtmlWriter, RspecApiDocumentation::Writers::JsonWriter,
72-
RspecApiDocumentation::Writers::TextileWriter]
71+
expect(subject.writers).to eq([RspecApiDocumentation::Writers::HtmlWriter,
72+
RspecApiDocumentation::Writers::JsonWriter,
73+
RspecApiDocumentation::Writers::TextileWriter])
7374
end
7475
end
7576

@@ -79,7 +80,7 @@ class RspecApiDocumentation::Writers::TextileWriter; end
7980
end
8081

8182
it "should return the classes from format" do
82-
subject.writers.should == [RspecApiDocumentation::Writers::HtmlWriter]
83+
expect(subject.writers).to eq([RspecApiDocumentation::Writers::HtmlWriter])
8384
end
8485
end
8586
end
@@ -90,13 +91,13 @@ class RspecApiDocumentation::Writers::TextileWriter; end
9091
let(:textile_writer) { double(:textile_writer) }
9192

9293
before do
93-
subject.stub(:writers => [html_writer, json_writer, textile_writer])
94+
allow(subject).to receive(:writers).and_return([html_writer, json_writer, textile_writer])
9495
end
9596

9697
it "should write the docs in each format" do
97-
html_writer.should_receive(:write).with(subject.index, configuration)
98-
json_writer.should_receive(:write).with(subject.index, configuration)
99-
textile_writer.should_receive(:write).with(subject.index, configuration)
98+
expect(html_writer).to receive(:write).with(subject.index, configuration)
99+
expect(json_writer).to receive(:write).with(subject.index, configuration)
100+
expect(textile_writer).to receive(:write).with(subject.index, configuration)
100101
subject.write
101102
end
102103
end

spec/api_formatter_spec.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,47 @@
1111

1212
before do
1313
RspecApiDocumentation.documentations.each do |configuration|
14-
configuration.stub(
15-
:clear_docs => nil,
16-
:document_example => nil,
17-
:write => nil
18-
)
14+
allow(configuration).to receive(:clear_docs)
15+
allow(configuration).to receive(:document_example)
16+
allow(configuration).to receive(:write)
1917
end
2018
end
2119

2220
it "should clear all docs on start" do
2321
RspecApiDocumentation.documentations.each do |configuration|
24-
configuration.should_receive(:clear_docs)
22+
expect(configuration).to receive(:clear_docs)
2523
end
2624

27-
formatter.start(0)
25+
formatter.start(RSpec::Core::Notifications::StartNotification.new(0, 0))
2826
end
2927

3028
it "should document passing examples" do
3129
example = group.example("Ordering a cup of coffee") {}
3230

3331
RspecApiDocumentation.documentations.each do |configuration|
34-
configuration.should_receive(:document_example).with(example)
32+
expect(configuration).to receive(:document_example).with(example)
3533
end
3634

37-
formatter.example_passed(example)
35+
formatter.example_passed(RSpec::Core::Notifications::ExampleNotification.for(example))
3836
end
3937

4038
it "should write the docs on stop" do
4139
RspecApiDocumentation.documentations.each do |configuration|
42-
configuration.should_receive(:write)
40+
expect(configuration).to receive(:write)
4341
end
4442

4543
formatter.stop
4644
end
4745
end
4846

4947
describe "output" do
48+
let(:reporter) { RSpec::Core::Reporter.new(RSpec::Core::Configuration.new) }
49+
5050
before do
5151
# don't do any work
52-
RspecApiDocumentation.stub(:documentations).and_return([])
52+
allow(RspecApiDocumentation).to receive(:documentations).and_return([])
53+
54+
reporter.register_listener formatter, :start, :example_group_started, :example_passed, :example_failed, :stop
5355
end
5456

5557
context "with passing examples" do
@@ -60,8 +62,8 @@
6062
end
6163

6264
it "should list the generated docs" do
63-
group.run(formatter)
64-
output.string.split($/).should eq([
65+
group.run(reporter)
66+
expect(output.string.split($/)).to eq([
6567
"Generating API Docs",
6668
" Orders",
6769
" * Ordering a cup of coffee",
@@ -74,13 +76,13 @@
7476
context "with failing examples" do
7577
before do
7678
group.example("Ordering a cup of coffee") {}
77-
group.example("Updating an order") { true.should eq(false) }
78-
group.example("Viewing an order") { true.should eq(false) }
79+
group.example("Updating an order") { expect(true).to eq(false) }
80+
group.example("Viewing an order") { expect(true).to eq(false) }
7981
end
8082

8183
it "should indicate failures" do
82-
group.run(formatter)
83-
output.string.split($/).should eq([
84+
group.run(reporter)
85+
expect(output.string.split($/)).to eq([
8486
"Generating API Docs",
8587
" Orders",
8688
" * Ordering a cup of coffee",

spec/configuration_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
describe ".add_setting" do
1414
it 'should allow creating a new setting' do
1515
RspecApiDocumentation::Configuration.add_setting :new_setting
16-
configuration.should respond_to(:new_setting)
17-
configuration.should respond_to(:new_setting=)
16+
expect(configuration).to respond_to(:new_setting)
17+
expect(configuration).to respond_to(:new_setting=)
1818
end
1919

2020
it 'should allow setting a default' do
2121
RspecApiDocumentation::Configuration.add_setting :new_setting, :default => "default"
22-
configuration.new_setting.should == "default"
22+
expect(configuration.new_setting).to eq("default")
2323
end
2424

2525
it "should allow the default setting to be a lambda" do
2626
RspecApiDocumentation::Configuration.add_setting :another_setting, :default => lambda { |config| config.new_setting }
27-
configuration.another_setting.should == "default"
27+
expect(configuration.another_setting).to eq("default")
2828
end
2929
end
3030

@@ -62,37 +62,37 @@
6262
it "should take a block" do
6363
called = false
6464
subject.define_group(:foo) { called = true }
65-
called.should eq(true)
65+
expect(called).to eq(true)
6666
end
6767

6868
it "should yield a sub-configuration" do
6969
subject.define_group(:foo) do |config|
70-
config.should be_a(described_class)
71-
config.parent.should equal(subject)
70+
expect(config).to be_a(described_class)
71+
expect(config.parent).to equal(subject)
7272
end
7373
end
7474

7575
it "should set the sub-configuration filter" do
7676
subject.define_group(:foo) do |config|
77-
config.filter.should eq(:foo)
77+
expect(config.filter).to eq(:foo)
7878
end
7979
end
8080

8181
it "should inherit its parents configurations" do
8282
subject.format = :json
8383
subject.define_group(:sub) do |config|
84-
config.format.should == :json
84+
expect(config.format).to eq(:json)
8585
end
8686
end
8787

8888
it "should scope the documentation directory" do
8989
subject.define_group(:sub) do |config|
90-
config.docs_dir.should == subject.docs_dir.join('sub')
90+
expect(config.docs_dir).to eq(subject.docs_dir.join('sub'))
9191
end
9292
end
9393
end
9494

95-
it { should be_a(Enumerable) }
95+
it { expect(subject).to be_a(Enumerable) }
9696

9797
it "should enumerate through recursively and include self" do
9898
configs = [subject]
@@ -105,7 +105,7 @@
105105
end
106106
end
107107
end
108-
subject.to_a.should eq(configs)
108+
expect(subject.to_a).to eq(configs)
109109
end
110110

111111
describe "#groups" do

0 commit comments

Comments
 (0)