spec/restspec/endpoints/dsl_spec.rb in restspec-0.0.4 vs spec/restspec/endpoints/dsl_spec.rb in restspec-0.1
- old
+ new
@@ -15,16 +15,16 @@
end.to change { Restspec::NamespaceStore.size }.by(1)
end
it 'creates a namespace with the given name as a string' do
dsl.namespace(:monkey) { }
- expect(Restspec::NamespaceStore.first.name).to eq('monkey')
+ expect(Restspec::NamespaceStore.get(:monkey).name).to eq('monkey')
end
it 'creates a namespace with the given base_path' do
dsl.namespace(:monkey, base_path: '/monkey') { }
- expect(Restspec::NamespaceStore.first.full_base_path).to eq('/monkey')
+ expect(Restspec::NamespaceStore.get(:monkey).full_base_path).to eq('/monkey')
end
it 'yields a Restspec::Endpoints::NamespaceDSL attached to the namespace to the block' do
namespace_dsl = OpenStruct.new(call: true)
@@ -37,23 +37,28 @@
dsl.namespace(:monkey) do
self.call
end
expect(namespace_dsl).to have_received(:call)
- expect(namespace_dsl.namespace).to eq(Restspec::NamespaceStore.first)
+ expect(namespace_dsl.namespace).to eq(Restspec::NamespaceStore.get(:monkey))
end
end
describe '#resource' do
+ before do
+ schema = Restspec::Schema::Schema.new(:monkey)
+ Restspec::SchemaStore.store(schema)
+ end
+
it 'creates a namespace with the base_path equals to /:name' do
dsl.resource(:monkeys) { }
- expect(Restspec::NamespaceStore.first.full_base_path).to eq('/monkeys')
+ expect(Restspec::NamespaceStore.get(:monkeys).full_base_path).to eq('/monkeys')
end
it 'creates a namespace with the schema attached to some schema with the same name' do
dsl.resource(:monkeys) { }
- expect(Restspec::NamespaceStore.first.schema_name).to eq(:monkey)
+ expect(Restspec::NamespaceStore.get(:monkeys).schema_for(:response).name).to eq(:monkey)
end
end
describe Restspec::Endpoints::NamespaceDSL do
let(:namespace) { Restspec::Endpoints::Namespace.new(:monkeys) }
@@ -84,18 +89,26 @@
end
end
end
describe '#schema' do
+ before do
+ Restspec::SchemaStore.store(Restspec::Schema::Schema.new(:schema_name))
+ end
+
it 'sets the schema_name of the namespace' do
expect do
ns_dsl.schema :schema_name
- end.to change { namespace.schema_name }.to(:schema_name)
+ end.to change { namespace.schema_for(:response).try(:name) }.to(:schema_name)
end
end
describe '#all' do
+ before do
+ Restspec::SchemaStore.store(Restspec::Schema::Schema.new(:a_schema_name))
+ end
+
it 'calls the same block in all the endpoints inside' do
ns_dsl.all do
schema :a_schema_name
end
@@ -103,12 +116,12 @@
ns_dsl.endpoint(:b) { }
endpoint_a = Restspec::EndpointStore.get('monkeys/a')
endpoint_b = Restspec::EndpointStore.get('monkeys/b')
- expect(endpoint_a.schema_name).to eq(:a_schema_name)
- expect(endpoint_b.schema_name).to eq(:a_schema_name)
+ expect(endpoint_a.schema_for(:response).name).to eq(:a_schema_name)
+ expect(endpoint_a.schema_for(:response).name).to eq(:a_schema_name)
end
end
describe '#url_param' do
it 'sets the url_params in each endpoint' do
@@ -194,24 +207,24 @@
endpoint_dsl.path '/hola'
}.to change { endpoint.full_path }.from(nil).to('/hola')
end
end
+ describe '#no_schema' do
+ it 'removes the schema' do
+ endpoint_dsl.schema :monkey
+ endpoint_dsl.no_schema
+ expect(endpoint.all_schemas).to eq([])
+ end
+ end
+
describe '#schema' do
- it 'sets the schema_name' do
+ it 'sets the schema for response' do
expect {
endpoint_dsl.schema :monkey
- }.to change { endpoint.schema_name }.from(nil).to(:monkey)
+ }.to change { endpoint.schema_for(:response).try(:name) }.from(nil).to(:monkey)
end
-
- it 'sets the schema_name with schema_extensions' do
- extensions = { a: 1, b: 2, c: 3 }
-
- expect {
- endpoint_dsl.schema :monkey, extensions
- }.to change { endpoint.schema_extensions }.from(nil).to(extensions)
- end
end
describe '#headers' do
it 'changes the headers of the endpoint' do
expect do
@@ -248,10 +261,10 @@
context 'when the endpoint has a schema' do
let(:schema) { double(attributes: { param: 1 }) }
before do
- allow(endpoint).to receive(:schema).and_return(schema)
+ allow(endpoint).to receive(:schema_for).and_return(schema)
end
it 'calls the example_for with the attribute from the schema' do
type = self.type