Suppose I have a third party lib that uses a DSL to perform its magic like the dsl.rb and runtime.rb files below. My application has a Consumer class that uses that API as shown in the consumer.rb file. How should I spec the say method to ensure the output method receives the correct parameter?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT e.id, ( | |
| SELECT CASE periodicity | |
| WHEN 'daily' THEN DATEDIFF('2011-01-08', s.starts_at) <= s.occurrences -1 | |
| WHEN 'weekly' THEN DAYOFWEEK('2011-01-08') = DAYOFWEEK(s.starts_at) AND '2011-01-08' < ADDDATE(s.starts_at, INTERVAL s.occurrences -1 WEEK) | |
| WHEN 'bi-weekly' THEN DATEDIFF('2011-01-08', s.starts_at) MOD 14 = 0 AND '2011-01-08' < ADDDATE(s.starts_at, INTERVAL s.occurrences -1 WEEK) | |
| WHEN 'monthly' THEN DAY('2011-01-08') = DAY(s.starts_at) AND '2011-01-08' < ADDDATE(s.starts_at, INTERVAL s.occurrences -1 MONTH) | |
| WHEN 'yearly' THEN DAY('2011-01-08') = DAY(s.starts_at) AND MONTH('2011-01-08') = MONTH(s.starts_at) AND '2011-01-08' < ADDDATE(s.starts_at, INTERVAL s.occurrences - 1 YEAR) | |
| END) AS matches | |
| FROM events AS e | |
| INNER JOIN schedules AS s ON (s.event_id = e.id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DatabaseImporter | |
| def initialize(sql_file) | |
| @sql_file = sql_file | |
| end | |
| def all_values | |
| tables_names.inject({}) { |memo,name| memo[name] = values_for(name); memo } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- encoding: utf-8 -*- | |
| Gem::Specification.new do |s| | |
| s.name = "activemodel" | |
| s.version = "3.1.3" | |
| s.required_rubygems_version = Gem::Requirement.new("[\">=\", #<Gem::Version \"0\">] ") if s.respond_to? :required_rubygems_version= | |
| s.authors = ["David Heinemeier Hansson"] | |
| s.date = "2011-11-20" | |
| s.description = "A toolkit for building modeling frameworks like Active Record and Active Resource. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [~]% echo $RBXOPT | |
| -Xrbc.db=/Users/samflores/.rbc -X19 | |
| [~]% ruby --version | |
| rubinius 2.0.0dev (1.9.3 e72fec95 yyyy-mm-dd JI) [x86_64-apple-darwin11.2.0] | |
| [~]% gem --version | |
| 1.8.10 | |
| [~]% gem i bundler --pre |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Number of restaurants with 5, 4, 3, 3, 1 and 0 average ratings | |
| SELECT stars_avg, count(stars_avg) | |
| FROM ( | |
| SELECT FLOOR(AVG(r.stars)) AS stars_avg | |
| FROM rates AS r | |
| JOIN venues AS v ON v.id = r.rateable_id | |
| JOIN types AS t ON t.id = v.type_id | |
| WHERE t.name = "Restaurants" | |
| AND r.rateable_type = "Venue" | |
| GROUP BY v.id) AS star_avgs_tbl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| v1.* | |
| FROM `venues` AS v1 | |
| WHERE ( | |
| v1.id in ( | |
| SELECT v2.id | |
| FROM `venues` AS v2 | |
| JOIN rates ON rates.rateable_id = v2.id | |
| WHERE (rates.rateable_type = 'Venue') | |
| GROUP BY v2.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'application' | |
| require 'capybara/dsl' | |
| require 'minitest/autorun' | |
| Capybara.app = Sinatra::Application | |
| set :environment, 'test' | |
| describe 'main application' do | |
| include Capybara::DSL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app.rb: main application file | |
| require 'sinatra' | |
| require 'libs' | |
| require 'models' | |
| require 'controllers' | |
| class App < Sinatra::Application | |
| include UsersController | |
| include ProjectsController |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| array = (1..10000).to_a | |
| block = proc { |i| i * 2 } | |
| Benchmark.bm(7) do |b| | |
| b.report('map') { array.map &block } | |
| b.report('collect') { array.collect &block } | |
| end | |
| # 1.9.3-p194-perf |