spec/lib/whipped-cream/server_spec.rb in whipped-cream-0.0.1 vs spec/lib/whipped-cream/server_spec.rb in whipped-cream-0.1.0
- old
+ new
@@ -1,16 +1,18 @@
require 'spec_helper'
describe WhippedCream::Server do
- subject(:server) { described_class.new(plugin) }
+ subject(:server) { described_class.new(plugin, options) }
let(:plugin) {
WhippedCream::Plugin.build do
button "Open/Close", pin: 1
end
}
+ let(:options) { Hash.new }
+
before do
Rack::Server.stub :start
end
it "creates a runner with the plugin" do
@@ -21,33 +23,75 @@
it "reuses the same runner" do
expect(server.runner).to eq(server.runner)
end
- it "builds up a Sinatra application from a plugin" do
- server.start
+ context "with a button" do
+ let(:plugin) {
+ WhippedCream::Plugin.build do
+ button "Open/Close", pin: 1
+ end
+ }
- expect(
- server.web.routes['GET'].find { |route| route.first.match('/open_close') }
- ).to be_true
+ before { server.start }
+
+ it "creates a button route" do
+ expect(server.web.routes['GET'].find { |route|
+ route.first.match('/open_close')
+ }).to be_true
+ end
end
+ context "with a switch" do
+ let(:plugin) {
+ WhippedCream::Plugin.build do
+ switch "Light", pin: 1
+ end
+ }
+
+ before { server.start }
+
+ it "creates a switch route" do
+ expect(server.web.routes['GET'].find { |route|
+ route.first.match('/light')
+ }).to be_true
+ end
+ end
+
describe "#start" do
it "starts a Rack server" do
expect(Rack::Server).to receive(:start).with(
- app: WhippedCream::Server::Web, port: 8080
+ app: WhippedCream::Web, Port: 8080, daemonize: false
)
server.start
end
context "with daemonize: true" do
- it "starts the Sinatra application" do
+ let(:options) {
+ { daemonize: true }
+ }
+
+ it "starts the Rack server daemonized" do
expect(Rack::Server).to receive(:start).with(
- app: WhippedCream::Server::Web, port: 8080, daemonize: true
+ app: WhippedCream::Web, Port: 8080, daemonize: true
)
- server.start(daemonize: true)
+ server.start
+ end
+ end
+
+ context "with port: 1234" do
+ let(:options) {
+ { port: 1234 }
+ }
+
+ it "starts the Rack server on a specific port" do
+ expect(Rack::Server).to receive(:start).with(
+ app: WhippedCream::Web, Port: 1234, daemonize: false
+ )
+
+ server.start
end
end
end
end