spec/acfs/stub_spec.rb in acfs-0.23.2.b209 vs spec/acfs/stub_spec.rb in acfs-0.23.2
- old
+ new
@@ -8,10 +8,14 @@
before(:all) { Acfs::Stub.enable }
after(:all) { Acfs::Stub.disable }
before do
Acfs::Stub.allow_requests = false
+
+ #Acfs::Stub.read(MyUser).with(id: 5).and_return({ id: 5, name: 'John', age: 32 })
+ #Acfs::Stub.read(MyUser).with(id: 6).and_raise(:not_found)
+ #Acfs::Stub.create(MyUser).with(name: '', age: 12).and_return(:invalid, errors: { name: [ 'must be present ']})
end
describe '#called?' do
context 'without specified number' do
let!(:operation) { Acfs::Stub.resource MyUser, :read, with: { id: 1 }, return: { id: 1, name: 'John Smith', age: 32 } }
@@ -76,27 +80,10 @@
MyUser.find 3
expect { Acfs.run }.to raise_error(Acfs::ResourceNotFound)
end
end
-
- context 'with type parameter' do
- before do
- Acfs::Stub.resource Computer, :read, with: { id: 1 }, return: { id: 1, type: 'PC' }
- Acfs::Stub.resource Computer, :read, with: { id: 2 }, return: { id: 2, type: 'Mac' }
- end
-
- it 'should create inherited type' do
- pc = Computer.find 1
- mac = Computer.find 2
-
- Acfs.run
-
- expect(pc).to be_a PC
- expect(mac).to be_a Mac
- end
- end
end
context 'with create action' do
before do
Acfs::Stub.resource Session, :create, with: { ident: 'john@exmaple.org', password: 's3cr3t' }, return: { id: 'longhash', user: 1 }
@@ -112,48 +99,9 @@
it 'should allow to raise error' do
expect {
Session.create! ident: 'john@exmaple.org', password: 'wrong'
}.to raise_error(::Acfs::InvalidResource)
- end
- end
-
- context 'with list action' do
- before do
- Acfs::Stub.resource MyUser, :list,
- return: [{ id: 1, name: 'John Smith', age: 32 }, { id: 2, name: 'Anon', age: 12 }]
- end
-
- it 'should return collection' do
- users = MyUser.all
- Acfs.run
-
- expect(users).to have(2).items
- end
-
- it 'should return defined resources' do
- users = MyUser.all
- Acfs.run
-
- expect(users[0].id).to eq 1
- expect(users[1].id).to eq 2
- expect(users[0].name).to eq 'John Smith'
- expect(users[1].name).to eq 'Anon'
- end
-
- context 'with type parameter' do
- before do
- Acfs::Stub.resource Computer, :list,
- return: [{id: 1, type: 'PC'}, {id: 2, type: 'Mac'}]
- end
-
- it 'should create inherited type' do
- computers = Computer.all
- Acfs.run
-
- expect(computers.first).to be_a PC
- expect(computers.last).to be_a Mac
- end
end
end
context 'with update action' do
before do