Skip to content

Update specs to RSpec 2.14.8 syntax #58

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
120 changes: 60 additions & 60 deletions spec/fdoc/endpoint_scaffold_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
}

before(:each) do
subject.request_parameters.should be_empty
expect(subject.request_parameters).to be_empty
end

it "creates properties for top-level keys, and populates them with examples" do
subject.consume_request(request_params, true)
subject.request_parameters["type"].should == nil
subject.request_parameters["properties"].should have(3).keys
subject.request_parameters["properties"]["depth"]["type"].should == "integer"
subject.request_parameters["properties"]["max_connections"]["example"].should == 20
subject.request_parameters["properties"]["root_node"]["type"].should == "string"
expect(subject.request_parameters["type"]).to eq(nil)
expect(subject.request_parameters["properties"].keys.size).to eq(3)
expect(subject.request_parameters["properties"]["depth"]["type"]).to eq("integer")
expect(subject.request_parameters["properties"]["max_connections"]["example"]).to eq(20)
expect(subject.request_parameters["properties"]["root_node"]["type"]).to eq("string")
end

it "infers boolean types" do
Expand All @@ -34,9 +34,9 @@
"hold_the_lettuce" => true
}
subject.consume_request(bool_params)
subject.request_parameters["properties"].should have(2).keys
subject.request_parameters["properties"]["with_cheese"]["type"].should == "boolean"
subject.request_parameters["properties"]["hold_the_lettuce"]["type"].should == "boolean"
expect(subject.request_parameters["properties"].keys.size).to eq(2)
expect(subject.request_parameters["properties"]["with_cheese"]["type"]).to eq("boolean")
expect(subject.request_parameters["properties"]["hold_the_lettuce"]["type"]).to eq("boolean")
end

context "infers formats" do
Expand All @@ -46,28 +46,28 @@
"time_obj" => Time.now
}
subject.consume_request(datetime_params)
subject.request_parameters["properties"].should have(2).keys
subject.request_parameters["properties"]["time_str"]["type"].should == "string"
subject.request_parameters["properties"]["time_str"]["format"].should == "date-time"
subject.request_parameters["properties"]["time_obj"]["type"].should == "string"
subject.request_parameters["properties"]["time_obj"]["format"].should == "date-time"
expect(subject.request_parameters["properties"].keys.size).to eq(2)
expect(subject.request_parameters["properties"]["time_str"]["type"]).to eq("string")
expect(subject.request_parameters["properties"]["time_str"]["format"]).to eq("date-time")
expect(subject.request_parameters["properties"]["time_obj"]["type"]).to eq("string")
expect(subject.request_parameters["properties"]["time_obj"]["format"]).to eq("date-time")
end

it "detects uri formats" do
uri_params = {
"sample_uri" => "http://my.example.com"
}
subject.consume_request(uri_params)
subject.request_parameters["properties"].should have(1).keys
subject.request_parameters["properties"]["sample_uri"]["type"].should == "string"
subject.request_parameters["properties"]["sample_uri"]["format"].should == "uri"
expect(subject.request_parameters["properties"].keys.size).to eq(1)
expect(subject.request_parameters["properties"]["sample_uri"]["type"]).to eq("string")
expect(subject.request_parameters["properties"]["sample_uri"]["format"]).to eq("uri")
end

it "detects color formats (hex only for now)" do
color_params = { "page_color" => "#AABBCC" }
subject.consume_request(color_params)
subject.request_parameters["properties"]["page_color"]["type"].should == "string"
subject.request_parameters["properties"]["page_color"]["format"].should == "color"
expect(subject.request_parameters["properties"]["page_color"]["type"]).to eq("string")
expect(subject.request_parameters["properties"]["page_color"]["format"]).to eq("color")
end
end

Expand All @@ -77,11 +77,11 @@
"with_string" => true
}
subject.consume_request(mixed_params)
subject.request_parameters["properties"].should have(2).keys
subject.request_parameters["properties"].should have_key "with_symbol"
subject.request_parameters["properties"].should_not have_key :with_symbol
subject.request_parameters["properties"].should have_key "with_string"
subject.request_parameters["properties"].should_not have_key :with_string
expect(subject.request_parameters["properties"].keys.size).to eq(2)
expect(subject.request_parameters["properties"]).to have_key "with_symbol"
expect(subject.request_parameters["properties"]).not_to have_key :with_symbol
expect(subject.request_parameters["properties"]).to have_key "with_string"
expect(subject.request_parameters["properties"]).not_to have_key :with_string
end

it "uses strings (not symbols) for keys of nested hashes" do
Expand All @@ -93,7 +93,7 @@
}

subject.consume_request(mixed_params)
subject.request_parameters["properties"]["nested_object"]["properties"].keys.sort.should == ["with_string", "with_symbol"]
expect(subject.request_parameters["properties"]["nested_object"]["properties"].keys.sort).to eq(["with_string", "with_symbol"])
end

it "uses strings (not symbols) for nested hashes inside arrays" do
Expand All @@ -107,13 +107,13 @@
}

subject.consume_request(mixed_params)
subject.request_parameters["properties"]["nested_array"]["items"]["properties"].keys.sort.should == ["with_string", "with_symbol"]
expect(subject.request_parameters["properties"]["nested_array"]["items"]["properties"].keys.sort).to eq(["with_string", "with_symbol"])
end

it "produces a valid JSON schema for the response" do
subject.consume_request(request_params)
subject.request_parameters["properties"].should have(3).keys
JSON::Validator.validate!(subject.request_parameters, request_params).should be_true
expect(subject.request_parameters["properties"].keys.size).to eq(3)
expect(JSON::Validator.validate!(subject.request_parameters, request_params)).to be_true
end
end

Expand Down Expand Up @@ -151,57 +151,57 @@

context "for succesful responses" do
before(:each) do
subject.should have(0).response_codes
expect(subject.response_codes.size).to eq(0)
end

it "adds response codes" do
subject.consume_response({}, "200 OK")
subject.should have(1).response_codes
expect(subject.response_codes.size).to eq(1)

subject.consume_response({}, "201 Created")
subject.should have(2).response_codes
expect(subject.response_codes.size).to eq(2)
end

it "does not add duplicate response codes" do
subject.consume_response({}, "200 OK")
subject.should have(1).response_codes
expect(subject.response_codes.size).to eq(1)

subject.consume_response({}, "200 OK")
subject.should have(1).response_codes
expect(subject.response_codes.size).to eq(1)

subject.response_codes.each do |response|
response["description"].should == "???"
expect(response["description"]).to eq("???")
end
end

it "creates properties for top-level keys, and populates them with examples" do
subject.consume_response(response_params, "200 OK")
subject.response_parameters["type"].should == nil
subject.response_parameters["properties"].keys.should =~ ["nodes", "root_node", "std_dev", "version", "updated_at"]
expect(subject.response_parameters["type"]).to eq(nil)
expect(subject.response_parameters["properties"].keys).to match_array(["nodes", "root_node", "std_dev", "version", "updated_at"])

subject.response_parameters["properties"]["nodes"]["type"].should == "array"
subject.response_parameters["properties"]["nodes"]["description"].should == "???"
subject.response_parameters["properties"]["nodes"]["required"].should == "???"
expect(subject.response_parameters["properties"]["nodes"]["type"]).to eq("array")
expect(subject.response_parameters["properties"]["nodes"]["description"]).to eq("???")
expect(subject.response_parameters["properties"]["nodes"]["required"]).to eq("???")

subject.response_parameters["properties"]["root_node"]["type"].should == "object"
subject.response_parameters["properties"]["root_node"]["description"].should == "???"
subject.response_parameters["properties"]["root_node"]["required"].should == "???"
expect(subject.response_parameters["properties"]["root_node"]["type"]).to eq("object")
expect(subject.response_parameters["properties"]["root_node"]["description"]).to eq("???")
expect(subject.response_parameters["properties"]["root_node"]["required"]).to eq("???")

subject.response_parameters["properties"]["version"]["type"].should == "integer"
subject.response_parameters["properties"]["std_dev"]["type"].should == "number"
expect(subject.response_parameters["properties"]["version"]["type"]).to eq("integer")
expect(subject.response_parameters["properties"]["std_dev"]["type"]).to eq("number")
end

it "populates items in arrays" do
subject.consume_response(response_params, "200 OK")
subject.response_parameters["properties"]["nodes"]["type"].should == "array"
subject.response_parameters["properties"]["nodes"]["items"]["type"].should == "object"
subject.response_parameters["properties"]["nodes"]["items"]["properties"].keys.sort.should == [
"id", "linked_to","name"]
expect(subject.response_parameters["properties"]["nodes"]["type"]).to eq("array")
expect(subject.response_parameters["properties"]["nodes"]["items"]["type"]).to eq("object")
expect(subject.response_parameters["properties"]["nodes"]["items"]["properties"].keys.sort).to eq([
"id", "linked_to","name"])
end

it "turns nil into null" do
subject.consume_response(response_params, "200 OK")
subject.response_parameters["properties"]["updated_at"]["type"].should == "null"
expect(subject.response_parameters["properties"]["updated_at"]["type"]).to eq("null")
end

it "uses strings (not symbols) as keys" do
Expand All @@ -210,32 +210,32 @@
"with_string" => true
}
subject.consume_response(mixed_params, "200 OK")
subject.response_parameters["properties"].should have(2).keys
subject.response_parameters["properties"].should have_key "with_symbol"
subject.response_parameters["properties"].should_not have_key :with_symbol
subject.response_parameters["properties"].should have_key "with_string"
subject.response_parameters["properties"].should_not have_key :with_string
expect(subject.response_parameters["properties"].keys.size).to eq(2)
expect(subject.response_parameters["properties"]).to have_key "with_symbol"
expect(subject.response_parameters["properties"]).not_to have_key :with_symbol
expect(subject.response_parameters["properties"]).to have_key "with_string"
expect(subject.response_parameters["properties"]).not_to have_key :with_string
end

it "produces a valid JSON schema for the response" do
subject.consume_response(response_params, "200 OK")
JSON::Validator.validate!(subject.response_parameters, response_params).should be_true
expect(JSON::Validator.validate!(subject.response_parameters, response_params)).to be_true
end
end

context "for unsuccessful responses" do
it "adds response codes" do
subject.should have(0).response_codes
expect(subject.response_codes.size).to eq(0)
subject.consume_response({}, "400 Bad Request", false)
subject.should have(1).response_codes
expect(subject.response_codes.size).to eq(1)
subject.consume_response({}, "404 Not Found", false)
subject.should have(2).response_codes
expect(subject.response_codes.size).to eq(2)
end

it "does not modify the response_parameters" do
subject.response_parameters.should be_empty
expect(subject.response_parameters).to be_empty
subject.consume_response(response_params, "403 Forbidden", false)
subject.response_parameters.should be_empty
expect(subject.response_parameters).to be_empty
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/fdoc/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def remove_optional(obj)

describe "#verb" do
it "infers the verb from the filename and service" do
subject.verb.should == "GET"
expect(subject.verb).to eq("GET")
end
end

describe "#path" do
it "infers its path from the filename and service" do
subject.path.should == "members/list"
expect(subject.path).to eq("members/list")
end
end

Expand All @@ -45,7 +45,7 @@ def remove_optional(obj)

context "with a well-behaved request" do
it "returns true" do
subject.should be_true
expect(subject).to be_true
end
end

Expand Down Expand Up @@ -110,18 +110,18 @@ def remove_optional(obj)
}

it "is successful" do
subject.should be_true
expect(subject).to be_true
end

context "with no optional keys" do
before { remove_optional(params) }

it "does not contain optional keys" do
params.keys.sort.should == ["required_nested_array", "required_nested_object", "toplevel_param"]
expect(params.keys.sort).to eq(["required_nested_array", "required_nested_object", "toplevel_param"])
end

it "is successful" do
subject.should be_true
expect(subject).to be_true
end
end

Expand Down Expand Up @@ -214,11 +214,11 @@ def remove_optional(obj)

context "for successful responses" do
it "validates the response parameters against the schema" do
subject.consume_response(good_response_params, "200 OK").should be_true
expect(subject.consume_response(good_response_params, "200 OK")).to be_true
end

it "allows either fully-qualified or integer HTTP status codes" do
subject.consume_response(good_response_params, 200).should be_true
expect(subject.consume_response(good_response_params, 200)).to be_true
end

context "with unknown keys" do
Expand All @@ -239,7 +239,7 @@ def remove_optional(obj)
context "when there is a valid success-code response" do
it "does not throw an error with bad response parameters" do
bad_params = good_response_params.merge({"extra_goodness" => true})
subject.consume_response(bad_params, "400 Bad Request", false).should be_true
expect(subject.consume_response(bad_params, "400 Bad Request", false)).to be_true
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/fdoc/presenters/base_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def to_html

context "#render_erb" do
it "renders a default template" do
File.should_receive(:exists?).with('templates/test.html.erb').and_return(false)
File.stub(:read).and_return('test content')
expect(File).to receive(:exists?).with('templates/test.html.erb').and_return(false)
allow(File).to receive(:read).and_return('test content')
subject.to_html
end

it "renders from local template directory" do
File.should_receive(:exists?).with('templates/test.html.erb').and_return(true)
File.should_receive(:read).with('templates/test.html.erb').and_return('test content')
expect(File).to receive(:exists?).with('templates/test.html.erb').and_return(true)
expect(File).to receive(:read).with('templates/test.html.erb').and_return('test content')
subject.to_html
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/fdoc/presenters/endpoint_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
context "#to_markdown" do
it "should generate markdown" do
markdown = subject.to_markdown
markdown.should include "# GET spec​/fixtures​/members​/list"
expect(markdown).to include "# GET spec​/fixtures​/members​/list"
end
end

Expand Down Expand Up @@ -94,7 +94,7 @@
}

it "should generate an example response from the contents of the schema" do
subject.example_from_schema(example_schema).should == expected_example
expect(subject.example_from_schema(example_schema)).to eq(expected_example)
end
end
end
8 changes: 4 additions & 4 deletions spec/fdoc/presenters/meta_service_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
context "#to_markdown" do
it "should generate markdown" do
markdown = subject.to_markdown
markdown.should include "* PUT [https:​/​/api.sample.com​/members​/add](members_api/add-PUT.md)"
markdown.should include "* POST [https:​/​/api.sample.com​/members​/draft](members_api/draft-POST.md)"
expect(markdown).to include "* PUT [https:​/​/api.sample.com​/members​/add](members_api/add-PUT.md)"
expect(markdown).to include "* POST [https:​/​/api.sample.com​/members​/draft](members_api/draft-POST.md)"
end
end

context "#relative_service_path" do
let(:service) { subject.services.first }

it "returns relative path" do
subject.relative_service_path(service).should == "members_api"
expect(subject.relative_service_path(service)).to eq("members_api")
end

it "should join relative path if passed in a filename" do
subject.relative_service_path(service, 'index.md').should == "members_api/index.md"
expect(subject.relative_service_path(service, 'index.md')).to eq("members_api/index.md")
end
end
end
8 changes: 4 additions & 4 deletions spec/fdoc/presenters/schema_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
it 'should generate valid HTML' do
html = subject.to_html

html.should include 'Some description text'
html.should include 'an example'
expect(html).to include 'Some description text'
expect(html).to include 'an example'
expect {
Nokogiri::HTML(html) { |config| config.strict }
}.to_not raise_exception
Expand All @@ -27,8 +27,8 @@
context "#to_markdown" do
it "should generate markdown" do
markdown = subject.to_markdown
markdown.should include 'Some description text'
markdown.should include 'an example'
expect(markdown).to include 'Some description text'
expect(markdown).to include 'an example'
end
end
end
Loading