Skip to content

Commit

Permalink
sorts out RSpec, dependencies, and spec Rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangreenberg committed Apr 27, 2011
1 parent 64fc4e5 commit 350f626
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 29 deletions.
29 changes: 29 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,29 @@
PATH
remote: .
specs:
arduino (0.0.1)
serialport (= 1.0.4)

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
rr (1.0.2)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
serialport (1.0.4)

PLATFORMS
ruby

DEPENDENCIES
arduino!
rr
rspec (~> 2.5.0)
serialport (= 1.0.4)
13 changes: 0 additions & 13 deletions README

This file was deleted.

19 changes: 19 additions & 0 deletions README.md
@@ -0,0 +1,19 @@
## Arduino ##
This gem makes it simple to connect to an Arduino board using Ruby.

Arduino is a wonderful little platform that includes a microcontroller, digital I/O, analog input, power, serial communication, and a great community. You can learn more about Arduino at http://arduino.cc.

## Why connect Arduino to your computer? ##
You can create standalone projects with Arduino using the provided IDE, but for some applications or quick prototypes it is convenient to connect the board to a computer.

- Control things on your computer with sensors connected to Arduino.
- Use your keyboard to send commands to your Arduino.
- Store data on you computer. Instead of using Arduino's 1KB of flash memory or buying a compatible SD card reader, record data you collect on your giant hard disk.
- Connect your Arduino to the world more easily. Instead of using an ethernet shield and dealing with networking on the Arduino board itself, just write Ruby and use libraries like openuri.

## Usage ##
require 'arduino'
port = '/dev/tty.usbserial-A7006AkP' # Depending on what port your device is connected to
arduino = Arduino::Board.new(:port => port)
arduino.connect
arduino.send("hello")
6 changes: 6 additions & 0 deletions Rakefile
@@ -1,2 +1,8 @@
$:.unshift 'lib'
require 'rspec/core/rake_task'
require 'bundler'
Bundler::GemHelper.install_tasks

desc "Run all specs"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
5 changes: 5 additions & 0 deletions arduino.gemspec
Expand Up @@ -18,4 +18,9 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency('serialport', '1.0.4')

s.add_development_dependency('rspec', '~> 2.5.0')
s.add_development_dependency('rr')
end
4 changes: 4 additions & 0 deletions lib/arduino.rb
@@ -1,2 +1,6 @@
module Arduino
end

require 'arduino/board'
require 'arduino/connector'
require 'arduino/version'
24 changes: 8 additions & 16 deletions arduino_spec.rb → spec/board_spec.rb
@@ -1,17 +1,9 @@
require 'rubygems'
require 'spec'
require 'rr'
Spec::Runner.configure do |config|
config.mock_with :rr
end
# extend RR::Adapters::RRMethods
require 'spec/spec_helper'

require 'arduino'

describe "Arduino" do
describe Arduino::Board do
describe "#new" do
it "should require a port" do
lambda { Arduino.new }.should raise_error
lambda { Arduino::Board.new }.should raise_error
end

it "should override default options with given options" do
Expand All @@ -22,22 +14,22 @@
:parity => SerialPort::NONE
}
options = overrides.merge :port => '/dev/tty.usbserial-A7006SoU'
mock(SerialPort).new(options[:port], overrides)
arduino = Arduino.new options
mock(SerialPort).new(options[:port], hash_including(overrides))
arduino = Arduino::Board.new options
end

it "open a connection to the specified serial port with the default options" do
port = '/dev/tty.usbserial-A7006SoU'
mock(SerialPort).new(
port,
{
hash_including(
:baud_rate => 9600,
:data_bits => 8,
:stop_bits => 1,
:parity => SerialPort::NONE
}
)
)
arduino = Arduino.new(:port => port)
arduino = Arduino::Board.new(:port => port)
end
end
end

0 comments on commit 350f626

Please sign in to comment.