Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

app spec fixed

  • Loading branch information...
commit 62c597068d051491154ed9a56e8174c2e6d4dbc4 1 parent b18b47f
Daniel Kirsch authored
Showing with 25 additions and 14 deletions.
  1. +5 −5 lib/detexify/base.rb
  2. +20 −9 spec/{app_spec.rb → latex_app_spec.rb}
10 lib/detexify/base.rb
View
@@ -66,15 +66,15 @@ def validate_id
def validate_strokes
begin
e('Illegal strokes') unless
- params[:strokes] # &&
- # strokes = JSON(params[:strokes]) &&
- # !strokes.empty? &&
- # !strokes.first.empty?
+ params[:strokes] &&
+ strokes = JSON(params[:strokes]) #&&
+ # !strokes.empty? &&
+ # !strokes.first.empty?
# TODO more thorough checks
rescue
e('Illegal strokes')
end
- strokes = JSON(params[:strokes])
+ strokes
end
def syms
29 spec/app_spec.rb → spec/latex_app_spec.rb
View
@@ -6,8 +6,7 @@
require 'yaml'
require 'json'
-TEST_CLASSIFIER = ENV['CLASSIFIER'] = 'http://localhost:99999'
-TESTCOUCH = ENV['COUCH'] = 'none'
+TEST_CLASSIFIER = ENV['CLASSIFIER'] = 'http://localhost:11678'
# fake the classifier
resp = JSON( File.open( File.dirname(__FILE__)+'/fixtures/counts.yml' ) { |yf| YAML::load( yf ) } )
FakeWeb.register_uri :get, TEST_CLASSIFIER, :body => resp
@@ -16,13 +15,22 @@
resp = JSON(:message => "Symbol was successfully trained.")
FakeWeb.register_uri :post, %r~#{TEST_CLASSIFIER}/train/.*~, :body => resp
-require 'app'
+require 'detexify/latex_app'
+
+# Detexify::LatexApp.set :classifier
def app
- Sinatra::Application
+ Detexify::LatexApp
end
-set :environment, :test
+class FakeCouch
+ def << *args
+ self
+ end
+end
+
+app.set :environment, :test
+app.set :couch, FakeCouch.new
describe 'Detexify' do
include Rack::Test::Methods
@@ -56,17 +64,17 @@ def app
it "won't train illegal ids" do
post '/train', {:id => 'bullshit', :strokes => JSON(@strokes)}
- last_response.status.should == 403
+ last_response.status.should == 400
end
it "won't train without strokes" do
post '/train', {:id => @symbol.id}
- last_response.status.should == 403
+ last_response.status.should == 400
end
it "won't train malformed strokes" do
post '/train', {:id => @symbol.id, :strokes => 'malformed'}
- last_response.status.should == 403
+ last_response.status.should == 400
end
it "lists symbols as json" do
@@ -78,9 +86,12 @@ def app
r.should be_a(Array)
r.each do |element|
element.should be_a(Hash)
- %w(id command mathmode textmode samples uri).each do |key|
+ %w(id symbol samples).each do |key|
element.should have_key(key)
end
+ %w(command mathmode textmode uri).each do |key|
+ element['symbol'].should have_key(key)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.