spec/lib/credy/rules_spec.rb in credy-0.2.0 vs spec/lib/credy/rules_spec.rb in credy-0.2.1
- old
+ new
@@ -1,22 +1,25 @@
require_relative '../../spec_helper'
describe Credy::Rules do
-
subject { Credy::Rules }
describe '.raw' do
it { should respond_to :raw }
- its(:raw) { should be_a Hash }
+
+ it 'is a hash' do
+ expect(subject.raw).to be_a Hash
+ end
end
describe '.all' do
+ it 'is a array' do
+ expect(subject.all).to be_a Array
+ end
- its(:all) { should be_a Array }
-
it 'contains a set of rules' do
- subject.stub(:raw).and_return({
+ allow(subject).to receive(:raw).and_return({
'visa' => {
'length' => [13, 16],
'countries' => {
'ch' => '404159',
'au' => '401795'
@@ -34,11 +37,11 @@
{prefix:"51", length:16, type:"mastercard"}
]
end
it 'works with string prefixes' do
- subject.stub(:raw).and_return({
+ allow(subject).to receive(:raw).and_return({
'visa' => {
'length' => [13, 16],
'countries' => {
'au' => '401795'
}
@@ -49,11 +52,11 @@
{prefix:"401795", length:[13, 16], type:"visa", country:"au"}
]
end
it 'works with integer prefixes' do
- subject.stub(:raw).and_return({
+ allow(subject).to receive(:raw).and_return({
'visa' => {
'length' => [13, 16],
'countries' => {
'au' => 401795
}
@@ -64,11 +67,11 @@
{prefix:"401795", length:[13, 16], type:"visa", country:"au"}
]
end
it 'works with an array of prefixes' do
- subject.stub(:raw).and_return({
+ allow(subject).to receive(:raw).and_return({
'visa' => {
'length' => [13, 16],
'countries' => {
'au' => ['401795', '404137']
}
@@ -82,13 +85,12 @@
end
end
describe '.filter' do
-
before do
- subject.stub(:raw).and_return({
+ allow(subject).to receive(:raw).and_return({
'visa' => {
'length' => [13, 16],
'countries' => {
'ch' => '404159',
'au' => '401795'
@@ -109,28 +111,26 @@
expect(subject.filter).to be_a Array
expect(subject.filter).to eq subject.all
end
it 'filters by type' do
- expect(subject.filter(type: 'visa')).to have(2).items
- expect(subject.filter(type: 'mastercard')).to have(1).item
+ expect(subject.filter(type: 'visa').length).to eq 2
+ expect(subject.filter(type: 'mastercard').length).to eq 1
end
it 'accepts the :country option' do
- expect(subject.filter(country: 'ch')).to have(1).item
- expect(subject.filter(country: 'au')).to have(2).items
+ expect(subject.filter(country: 'ch').length).to eq 1
+ expect(subject.filter(country: 'au').length).to eq 2
end
it 'accepts several options at the same time' do
rules = subject.filter type: 'visa', country: 'au'
- expect(rules).to have(1).item
+ expect(rules.length).to eq 1
end
it 'returns an empty array if nothing is found' do
rules = subject.filter type: 'foo', country: 'bar'
expect(rules).to be_a Array
expect(rules).to be_empty
end
-
end
-
end