diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..5f16476 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format progress diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 58170c7..2995527 --- a/Rakefile +++ b/Rakefile @@ -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 \ No newline at end of file diff --git a/spec/biju/modem_spec.rb b/spec/biju/modem_spec.rb deleted file mode 100644 index 6da75ce..0000000 --- a/spec/biju/modem_spec.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/spec/biju/parser_spec.rb b/spec/biju/parser_spec.rb new file mode 100644 index 0000000..87c2422 --- /dev/null +++ b/spec/biju/parser_spec.rb @@ -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 diff --git a/spec/biju/sms_spec.rb b/spec/biju/sms_spec.rb index 0cca416..7a4c428 100644 --- a/spec/biju/sms_spec.rb +++ b/spec/biju/sms_spec.rb @@ -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"} -end \ No newline at end of file + 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 diff --git a/spec/biju/to_hayes_spec.rb b/spec/biju/to_hayes_spec.rb new file mode 100644 index 0000000..f03d7f1 --- /dev/null +++ b/spec/biju/to_hayes_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0649f8..dbc4f1a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,17 @@ -require 'minitest/autorun' -require "./lib/biju" \ No newline at end of file +# 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