Permalink
Browse files

Start the app, and create a displayable Step.

  • Loading branch information...
piisalie committed Sep 21, 2015
0 parents commit df85555e95b6ee08d83ac020a61d3b3a2c6d5da5
Showing with 248 additions and 0 deletions.
  1. +2 −0 .rspec
  2. +7 −0 Gemfile
  3. +36 −0 Gemfile.lock
  4. +27 −0 app.rb
  5. +3 −0 config.ru
  6. +1 −0 lib/.#step.rb
  7. +17 −0 lib/step.rb
  8. +96 −0 spec/spec_helper.rb
  9. +37 −0 spec/step_spec.rb
  10. +8 −0 views/layout.mote
  11. +1 −0 views/recipes/show.mote
  12. +13 −0 views/recipes/step.mote
2 .rspec
@@ -0,0 +1,2 @@
--color
--require spec_helper
@@ -0,0 +1,7 @@
source 'https://rubygems.org'
gem 'rake', '~> 10.4.2'
gem 'rspec'
gem 'cuba', '~> 3.4.0'
gem 'mote'
gem 'mote-render'
@@ -0,0 +1,36 @@
GEM
remote: https://rubygems.org/
specs:
cuba (3.4.0)
rack
diff-lcs (1.2.5)
mote (1.1.4)
mote-render (1.1.0)
rack (1.6.4)
rake (10.4.2)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
PLATFORMS
ruby
DEPENDENCIES
cuba (~> 3.4.0)
mote
mote-render
rake (~> 10.4.2)
rspec
BUNDLED WITH
1.10.5
27 app.rb
@@ -0,0 +1,27 @@
require 'cuba'
require 'mote'
require 'mote/render'
require_relative 'lib/step'
class FakeDB
def self.get_step(recipe_id:, step_number:)
recipes = [ [ { directions: "Mix a lot, sir", ingredients: [ :pears ]} ] ]
recipes[(recipe_id.to_i - 1)][(step_number.to_i - 1)]
end
end
Cuba.plugin(Mote::Render)
Cuba.define do
on "recipes/(\\d+)" do |id|
res.write view("recipes/show", id: id)
end
on "recipes/(\\d+)-step-(\\d+)" do |recipe_id, step_number|
step = Step.find(recipe_id: recipe_id, step_number: step_number, database_wrapper: FakeDB)
res.write view("recipes/step", step: step)
end
end
@@ -0,0 +1,3 @@
require './app'
run(Cuba)
@@ -0,0 +1,17 @@
class Step
def self.find(recipe_id:, step_number:, database_wrapper:)
new(database_wrapper.get_step(recipe_id: recipe_id, step_number: step_number))
end
attr_reader :directions, :ingredients
def initialize(directions:, ingredients: [])
@directions = directions
@ingredients = ingredients
end
def has_ingredients?
ingredients.any?
end
end
@@ -0,0 +1,96 @@
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
config.disable_monkey_patching!
# This setting enables warnings. It's recommended, but in some cases may
# be too noisy due to issues in dependencies.
config.warnings = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# 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
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end
@@ -0,0 +1,37 @@
require_relative '../lib/step'
describe Step do
let(:directions) { "Mix a lot" }
let(:ingredients) { [ :pears, :honey ] }
def build_a_step(directions: "", ingredients: [])
Step.new(directions: directions, ingredients: ingredients)
end
it "has a .find interface" do
dummy_db = double
allow(dummy_db).to receive(:get_step)
.with(recipe_id: 1, step_number: 2) { { directions: directions } }
expect(Step.find(recipe_id: 1, step_number: 2, database_wrapper: dummy_db)).to be_a(Step)
end
it "can have ingredients" do
step = build_a_step(ingredients: ingredients)
expect(step.ingredients).to eq(ingredients)
end
it "knows if it has any ingredients" do
step = build_a_step
expect(step.has_ingredients?).to be(false)
step_with_ingredients = build_a_step(ingredients: ingredients)
expect(step_with_ingredients.has_ingredients?).to be true
end
it "has directions" do
step = build_a_step(directions: directions)
expect(step.directions).to eq(directions)
end
end
@@ -0,0 +1,8 @@
<html>
<head>
<title>Recipeat</title>
</head>
<body>
{{ content }}
</body>
</html>
@@ -0,0 +1 @@
{{id}}
@@ -0,0 +1,13 @@
<step>
% if step.has_ingredients?
<ingredient>
{{ step.ingredients }}
</ingredients>
% end
<directions>
{{ step.directions }}
</direction>
</step>

0 comments on commit df85555

Please sign in to comment.