Skip to content

Instantly share code, notes, and snippets.

@dbose
Created February 1, 2014 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbose/73f30d65efa8f29fce16 to your computer and use it in GitHub Desktop.
Save dbose/73f30d65efa8f29fce16 to your computer and use it in GitHub Desktop.
Ingredient Parsing Specs
# encoding: utf-8
require 'spec_helper'
describe IngredientParser do
it "should parse - <12 cups lettuce>" do
ingredient = IngredientParser.parse("12 cups lettuce")
ingredient.should_not be_blank
ingredient.quantity.should == "12"
ingredient.unit.should == "cup"
ingredient.base.should == "lettuce"
end
it "should parse - <14 large, fresh eggs>" do
ingredient = IngredientParser.parse("14 large, fresh eggs")
ingredient.should_not be_blank
ingredient.quantity.should == "14"
ingredient.base.should == "eggs"
ingredient.state.should == "large fresh"
end
it "should parse - <1 1/2 tbsp olive oil>" do
ingredient = IngredientParser.parse("1 1/2 tbsp olive oil")
ingredient.should_not be_blank
ingredient.quantity.should == "1 1/2"
ingredient.unit.should == "tbsp"
ingredient.base.should == "olive oil"
end
it "should parse - <1 (12 ounce) package tofu>" do
ingredient = IngredientParser.parse("1 (12 ounce) package tofu")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "package"
ingredient.base.should == "tofu"
end
it "should parse - <apple, cored, peeled>" do
ingredient = IngredientParser.parse("apple, cored, peeled")
ingredient.should_not be_blank
ingredient.quantity.should be_blank
ingredient.unit.should be_blank
ingredient.base.should == "apple"
ingredient.state.should == "cored peeled"
end
it "should parse - <2 tsp crushed garlic>" do
ingredient = IngredientParser.parse("2 tsp crushed garlic")
ingredient.should_not be_blank
ingredient.quantity.should == "2"
ingredient.unit.should == "tsp"
ingredient.base.should == "garlic"
ingredient.state.should == "crushed"
end
it "should parse - <1/2 cup crumbled feta>" do
ingredient = IngredientParser.parse("1/2 cup crumbled feta")
ingredient.should_not be_blank
ingredient.quantity.should == "1/2"
ingredient.unit.should == "cup"
ingredient.base.should == "feta"
ingredient.state.should == "crumbled"
end
it "should parse - <1-2 tsp. fresh lime juice>" do
ingredient = IngredientParser.parse("1-2 tsp. fresh lime juice")
ingredient.should_not be_blank
ingredient.quantity.should == "1-2"
ingredient.unit.should == "tsp."
ingredient.base.should == "lime juice"
ingredient.state.should == "fresh"
end
it "should parse - <salt, for drawing water out of cucumber>" do
ingredient = IngredientParser.parse("salt, for drawing water out of cucumber")
ingredient.should_not be_blank
ingredient.quantity.should be_blank
ingredient.unit.should be_blank
ingredient.base.should == "salt"
ingredient.state.should be_blank
end
it "should parse - <salt to taste>" do
ingredient = IngredientParser.parse("salt to taste")
ingredient.should_not be_blank
ingredient.quantity.should be_blank
ingredient.unit.should be_blank
ingredient.base.should == "salt"
ingredient.state.should be_blank
end
it "should parse - <pinch of salt>" do
ingredient = IngredientParser.parse("pinch of salt")
ingredient.should_not be_blank
ingredient.quantity.should be_blank
ingredient.unit.should == "pinch"
ingredient.base.should == "salt"
ingredient.state.should be_blank
end
it "should parse - <a pinch of salt>" do
ingredient = IngredientParser.parse("a pinch of salt")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "pinch"
ingredient.base.should == "salt"
ingredient.state.should be_blank
end
it "should parse - <pepper>" do
ingredient = IngredientParser.parse("pepper")
ingredient.should_not be_blank
ingredient.quantity.should be_blank
ingredient.unit.should be_blank
ingredient.base.should == "pepper"
ingredient.state.should be_blank
end
it "should parse - <4 to 6 pitas>" do
ingredient = IngredientParser.parse("4 to 6 pitas")
ingredient.should_not be_blank
ingredient.quantity.should == "4 to 6"
ingredient.unit.should be_blank
ingredient.base.should == "pitas"
ingredient.state.should be_blank
end
it "should parse - <salt and pepper>" do
ingredient = IngredientParser.parse("salt and pepper")
ingredient.should_not be_blank
ingredient.quantity.should be_blank
ingredient.unit.should be_blank
ingredient.base.should == "salt and pepper"
ingredient.state.should be_blank
end
it "should parse - <1 7- to 8-ounce block feta cheese, sliced>" do
ingredient = IngredientParser.parse("1 7- to 8-ounce block feta cheese, sliced")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "7- to 8-ounce block"
ingredient.base.should == "feta cheese"
ingredient.state.should == "sliced"
end
it "should parse - <4 slices of tomato>" do
ingredient = IngredientParser.parse("4 slices of tomato")
ingredient.should_not be_blank
ingredient.quantity.should == "4"
ingredient.unit.should == "slice"
ingredient.base.should == "tomato"
ingredient.state.should be_blank
end
it "should parse - <About 3.5 ounces sun-dried tomatoes, plus some of the oil from the jar or container>" do
ingredient = IngredientParser.parse("About 3.5 ounces sun-dried tomatoes, plus some of the oil from the jar or container")
ingredient.should_not be_blank
ingredient.quantity.should == "3.5"
ingredient.unit.should == "ounce"
ingredient.base.should == "sun-dried tomatoes"
ingredient.state.should be_blank
end
it "should parse - <1/4 cup plus 2 tablespoons grated Parmesan cheese>" do
ingredient = IngredientParser.parse("1/4 cup plus 2 tablespoons grated Parmesan cheese")
ingredient.should_not be_blank
ingredient.quantity.should == "1/4"
ingredient.unit.should == "cup"
ingredient.base.should == "Parmesan cheese"
ingredient.state.should == "grated"
end
it "should parse - <2 tablespoons butter; melted>" do
ingredient = IngredientParser.parse("2 tablespoons butter; melted")
ingredient.should_not be_blank
ingredient.quantity.should == "2"
ingredient.unit.should == "tablespoon"
ingredient.base.should == "butter"
ingredient.state.should == "melted"
end
it "should parse - <1 pound spinach, rinsed and torn into bite-size pieces>" do
ingredient = IngredientParser.parse("1 pound spinach, rinsed and torn into bite-size pieces")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "pound"
ingredient.base.should == "spinach"
ingredient.state.should be_blank
end
it "should parse - <1 c of sugar>" do
ingredient = IngredientParser.parse("1 c of sugar")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "c"
ingredient.base.should == "sugar"
ingredient.state.should be_blank
end
it "should parse - <2 garlic cloves, minced>" do
ingredient = IngredientParser.parse("2 garlic cloves, minced")
ingredient.should_not be_blank
ingredient.quantity.should == "2"
ingredient.unit.should == "clove"
ingredient.base.should == "garlic"
ingredient.state.should == "minced"
end
it "should parse - <½ teaspoon salt>" do
ingredient = IngredientParser.parse("½ teaspoon salt")
ingredient.should_not be_blank
ingredient.quantity.should == "1/2"
ingredient.unit.should == "teaspoon"
ingredient.base.should == "salt"
end
it "should parse - <Two 15-ounce cans chickpeas (4 cups), rinsed and drained>" do
ingredient = IngredientParser.parse("Two 15-ounce cans chickpeas (4 cups), rinsed and drained")
ingredient.should_not be_blank
ingredient.quantity.should == "2"
ingredient.unit.should == "15-ounce cans"
ingredient.base.should == "chickpeas"
end
it "should parse - 1 bag(s) shreadded cheese" do
ingredient = IngredientParser.parse("1 bag(s) shreadded cheese")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "bag"
ingredient.base.should == "shreadded cheese"
end
it "should parse - <10 eggs, lightly beaten>" do
ingredient = IngredientParser.parse("10 eggs, lightly beaten")
ingredient.should_not be_blank
ingredient.quantity.should == "10"
ingredient.unit.should be_blank
ingredient.base.should == "eggs"
ingredient.state.should == "lightly beaten"
end
it "should parse <1/2 cup sliced mushrooms (optional)>" do
ingredient = IngredientParser.parse("1/2 cup sliced mushrooms (optional)")
ingredient.should_not be_blank
ingredient.quantity.should == "1/2"
ingredient.unit.should == "cup"
ingredient.base.should == "mushrooms"
end
it "should parse <1 lb / 16 oz / 450 g baby broccoli / broccolini, trimmed, and each stalk halved if you like>" do
ingredient = IngredientParser.parse("1 lb / 16 oz / 450 g baby broccoli / broccolini, trimmed, and each stalk halved if you like")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "lb"
ingredient.base.should == "broccoli / broccolini"
ingredient.state.should == "baby"
end
it "should parse <3 bunches scallions, trimmed and thinly sliced>" do
ingredient = IngredientParser.parse("3 bunches scallions, trimmed and thinly sliced")
ingredient.should_not be_blank
ingredient.quantity.should == "3"
ingredient.unit.should == "bunch"
ingredient.base.should == "scallions"
end
it "should parse <1 small serrano chile pepper, deveined, seeded and minced (opt)>" do
ingredient = IngredientParser.parse("1 small serrano chile pepper, deveined, seeded and minced (opt)")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should be_blank
ingredient.base.should == "serrano chile pepper"
end
it "should parse <1/2 cup / 120 ml extra virgin olive oil>" do
ingredient = IngredientParser.parse("1/2 cup / 120 ml extra virgin olive oil")
ingredient.should_not be_blank
ingredient.quantity.should == "1/2"
ingredient.unit.should == "cup"
ingredient.base.should == "olive oil"
ingredient.state.should == "extra virgin"
end
it "should parse <4 - 6 oz fresh mozzarella cheese, torn into big chunks>" do
ingredient = IngredientParser.parse("4 - 6 oz fresh mozzarella cheese, torn into big chunks")
ingredient.should_not be_blank
ingredient.quantity.should == "4 - 6"
ingredient.unit.should == "oz"
ingredient.base.should == "mozzarella cheese"
ingredient.state.should == "fresh"
end
it "should parse - <1 (14 ounce) can diced tomatoes>" do
ingredient = IngredientParser.parse("1 (14 ounce) can diced tomatoes")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "can"
ingredient.base.should == "tomatoes"
ingredient.state.should == "diced"
end
it "should not split - 3/4 cup almonds, blanched and slivered" do
IngredientLine.should_split("3/4 cup almonds, blanched and slivered").should == false
end
it "should not split - Grated zest and juice of 1 orange" do
IngredientLine.should_split("Grated zest and juice of 1 orange").should == true
end
it "should not split - two large onions, a can of chopped tomatoes and 1/2 leek" do
IngredientLine.should_split("two large onions, a can of chopped tomatoes and 1/2 leek").should == true
end
it "should not split - two large onions, a can of chopped tomatoes" do
IngredientLine.should_split("two large onions, a can of chopped tomatoes").should == true
end
it "should not split - apple, peeled" do
IngredientLine.should_split("apple, peeled").should == false
end
it "should not split - icing sugar, to dust" do
IngredientLine.should_split("icing sugar, to dust").should == false
end
it "should not split - 7 slices of turkey bacon, or more to taste" do
IngredientLine.should_split("7 slices of turkey bacon, or more to taste").should == false
end
it "should not split - 10 eggs, lightly beaten" do
IngredientLine.should_split("10 eggs, lightly beaten").should == false
end
it "should parse - <1 (12-to 14-pounds) boneless or semiboneless fully cooked ham at room temperature 1 hour>" do
ingredient = IngredientParser.parse("1 (12-to 14-pounds) boneless or semiboneless fully cooked ham at room temperature 1 hour")
ingredient.should_not be_blank
ingredient.quantity.should == "1"
ingredient.unit.should == "can"
ingredient.base.should == "tomatoes"
ingredient.state.should == "diced"
end
it "should parse - <2 (3- to 3-1/2-pound) broiler chicken, cut into 8 pieces (ask your butcher to do this)>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment