Add tests using Rspec

develop
Guillaume DOTT 2013-09-03 17:03:40 +02:00
parent 34224a072c
commit 75509ac23a
7 changed files with 96 additions and 32 deletions

2
.rspec 100644
View File

@ -0,0 +1,2 @@
--color
--format progress

8
Rakefile 100644 → 100755
View File

@ -1,9 +1 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs.push "lib"
t.test_files = FileList['spec/**/*_spec.rb']
t.verbose = true
end

View File

@ -1,10 +0,0 @@
require_relative '../spec_helper'
# TODO: Fix missing tests SOON
describe Biju::Modem do
describe ".new" do
it "should raise an Exception without port option" do
lambda { Biju::Modem.new }.must_raise Exception
end
end
end

View File

@ -0,0 +1,53 @@
require 'spec_helper'
require 'biju/parser'
describe Biju::ATParser do
context "status" do
it "returns ok status" do
result = Biju::ATTransform.new.apply(Biju::ATParser.new.parse("OK\r"))
expect(result).to include(status: true)
end
it "returns error status" do
result = Biju::ATTransform.new.apply(Biju::ATParser.new.parse("ERROR\r"))
expect(result).to include(status: false)
end
end
context "response" do
it "parses messages list" do
messages = '+CMGL: 1,"REC READ","+85291234567",,"07/02/18,01:12:12+32"' <<
"\r" <<
"Reading text messages is easy.\r" <<
'+CMGL: 2,"REC READ","+85291234567",,"07/02/18,00:07:22+32"' <<
"\r" <<
"A simple demo of SMS text messaging.\r" <<
'+CMGL: 3,"REC READ","+85291234567",,"07/02/18,00:12:05+32"' <<
"\r" <<
"Hello, welcome to our SMS tutorial.\r" <<
"\r" <<
"OK\r"
result = Biju::ATTransform.new.apply(
Biju::ATParser.new.parse(messages))
expect(result).to include(status: true)
expect(result[:sms]).to have(3).messages
expect(result[:sms][0][:message]).to eq('Reading text messages is easy.')
end
it "gets messages storage" do
pms = "+CPMS: ((\"SM\",\"BM\",\"SR\"),(\"SM\"))\r"
result = Biju::ATTransform.new.apply(
Biju::ATParser.new.parse(pms))
expect(result[:cmd]).to eq('+CPMS')
expect(result[:array]).to have(2).storage
expect(result[:array][0]).to have(3).storage
end
end
it "raises ParseFailed exception" do
expect { Biju::ATParser.new.parse('Ha') }.to raise_error(Parslet::ParseFailed)
end
end

View File

@ -1,15 +1,17 @@
require_relative '../spec_helper'
require 'spec_helper'
require 'biju/sms'
describe Biju::Sms do
subject { Biju::Sms.new(:id => "1", :phone_number => "144", :datetime => "11/07/28,15:34:08-12", :message => "Some text here")}
subject do
Biju::Sms.new(
id: 1,
phone_number: "144",
datetime: "11/07/28,15:34:08-12",
message: "Some text here")
end
it { subject.id.must_equal "1" }
it { subject.phone_number.must_equal "144" }
it { subject.datetime.must_equal "2011-07-28 15:34:08" }
it { subject.message.must_equal "Some text here" }
it { subject.to_s.must_equal "1 - 144 - 2011-07-28 15:34:08 - Some text here"}
its(:id) { should eq(1) }
its(:phone_number) { should eq("144") }
its(:datetime) { should eq(DateTime.new(2011, 7, 28, 15, 34, 8)) }
its(:message) { should eq("Some text here") }
end

View File

@ -0,0 +1,10 @@
require 'spec_helper'
require 'biju/to_hayes'
describe "blah blah" do
it { expect(5.to_hayes).to eq('5') }
it { expect(true.to_hayes).to eq('1') }
it { expect(false.to_hayes).to eq('0') }
it { expect("test".to_hayes).to eq('"test"') }
it { expect([1, 2].to_hayes).to eq('1,2') }
end

View File

@ -1,2 +1,17 @@
require 'minitest/autorun'
require "./lib/biju"
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end