Seconda implementazione BDD
Created
June 5, 2012 23:45
-
-
Save stefanoverna/2878916 to your computer and use it in GitHub Desktop.
Seconda implementazione
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
| - | |
| ChangeLog.md | |
| LICENSE.txt |
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
| Gemfile.lock | |
| doc/ | |
| pkg/ | |
| vendor/cache/*.gem |
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
| --colour --format documentation |
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
| --markup markdown --title "redditor Documentation" --protected |
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 'thor' | |
| require 'redditor/story' | |
| require 'redditor/stories_printer' | |
| module Redditor | |
| class CLI < Thor | |
| desc "hot", "Shows the hottest stories on Reddit" | |
| def hot | |
| stories = Story.find(type: :hot) | |
| StoriesPrinter.output(stories) | |
| end | |
| end | |
| 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
| require 'redditor/cli' | |
| require 'stringio' | |
| module CLIMacros | |
| attr_reader :output, :error | |
| def redditor(command) | |
| out = StringIO.new | |
| err = StringIO.new | |
| begin | |
| $stdout = out | |
| $stderr = err | |
| cmd = cmd.kind_of?(Array) ? command : shell_split(command) | |
| Redditor::CLI.start(cmd) | |
| ensure | |
| $stdout = STDOUT | |
| $stderr = STDERR | |
| end | |
| raise RuntimeError, @error if @error.present? | |
| end | |
| def shell_split(line) | |
| words = [] | |
| field = '' | |
| line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do | |
| |word, sq, dq, esc, garbage, sep| | |
| raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage | |
| field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1')) | |
| if sep | |
| words << field | |
| field = '' | |
| end | |
| end | |
| words | |
| end | |
| end | |
| RSpec.configuration.include CLIMacros |
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 'spec_helper' | |
| require 'redditor/cli' | |
| describe Redditor::CLI do | |
| describe ".hot" do | |
| it "fetches /hot.json stories, and prints them out" do | |
| stories = double("stories array") | |
| Redditor::Story.stub(:find).with(type: :hot).and_return(stories) | |
| Redditor::StoriesPrinter.should_receive(:output).with(stories) | |
| subject.hot | |
| end | |
| end | |
| 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
| module FixtureMacros | |
| def fixture(path) | |
| File.expand_path("../../fixtures/#{path}", __FILE__) | |
| end | |
| def read_fixture(path) | |
| File.read(fixture(path)).strip | |
| end | |
| end | |
| RSpec.configuration.include FixtureMacros | |
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
| source :rubygems | |
| gemspec | |
| group :development do | |
| gem 'kramdown' | |
| gem 'rubygems-tasks', '~> 0.2' | |
| gem 'rspec', '~> 2.4' | |
| gem 'yard', '~> 0.7' | |
| gem 'bundler', '~> 1.0' | |
| gem 'rake', '~> 0.8' | |
| 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
| Copyright (c) 2012 Stefano Verna | |
| Permission is hereby granted, free of charge, to any person obtaining | |
| a copy of this software and associated documentation files (the | |
| "Software"), to deal in the Software without restriction, including | |
| without limitation the rights to use, copy, modify, merge, publish, | |
| distribute, sublicense, and/or sell copies of the Software, and to | |
| permit persons to whom the Software is furnished to do so, subject to | |
| the following conditions: | |
| The above copyright notice and this permission notice shall be | |
| included in all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
| LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
| OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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 | |
| require 'rubygems' | |
| begin | |
| require 'bundler' | |
| rescue LoadError => e | |
| warn e.message | |
| warn "Run `gem install bundler` to install Bundler." | |
| exit e.status_code | |
| end | |
| begin | |
| Bundler.setup(:development) | |
| rescue Bundler::BundlerError => e | |
| warn e.message | |
| warn "Run `bundle install` to install missing gems." | |
| exit e.status_code | |
| end | |
| require 'rake' | |
| require 'rubygems/tasks' | |
| Gem::Tasks.new | |
| require 'rspec/core/rake_task' | |
| RSpec::Core::RakeTask.new | |
| task :test => :spec | |
| task :default => :spec | |
| require 'yard' | |
| YARD::Rake::YardocTask.new | |
| task :doc => :yard |
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
| #!/usr/bin/env ruby | |
| require 'redditor/cli' | |
| Redditor::CLI.start |
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 -*- | |
| require File.expand_path('../lib/redditor/version', __FILE__) | |
| Gem::Specification.new do |gem| | |
| gem.name = "redditor" | |
| gem.version = Redditor::VERSION | |
| gem.summary = %q{TODO: Summary} | |
| gem.description = %q{Browse Reddit from CLI} | |
| gem.license = "MIT" | |
| gem.authors = ["Stefano Verna"] | |
| gem.email = "stefano.verna@welaika.com" | |
| gem.homepage = "https://github.com/stefanoverna/redditor#readme" | |
| gem.files = `git ls-files`.split($/) | |
| gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | |
| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | |
| gem.require_paths = ['lib'] | |
| gem.add_dependency 'activesupport' | |
| gem.add_dependency 'thor' | |
| gem.add_dependency 'command_line_reporter' | |
| gem.add_dependency 'json' | |
| gem.add_dependency 'googl' | |
| gem.add_dependency 'rest-client' | |
| gem.add_dependency 'launchy' | |
| gem.add_development_dependency 'bundler', '~> 1.0' | |
| gem.add_development_dependency 'yard', '~> 0.7' | |
| 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
| require 'redditor/version' | |
| module Redditor | |
| 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
| ββββββ³βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³βββββββββββββ³βββββββββββββββββββββββ | |
| β # β Story β Pts/Comms. β URL β | |
| β£ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ« | |
| β 1 β E3, We want games and gameplay, not this β 3536/1835 β http://goo.gl/86i6k β | |
| β£ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ« | |
| β 2 β TIL over 99% of birds "cleaned" after an oil spill die within weeks. C β 2129/422 β http://goo.gl/yHag β | |
| β β leaning birds is seen by many as merely a PR stunt by oil companies. β β β | |
| β£ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ« | |
| β 3 β Teen mom: their kids [first] world problem β 2442/267 β http://goo.gl/Pz3tN β | |
| β£ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ« | |
| β 4 β Norway goes secular, removes Lutheran Church as state religion β 2379/542 β http://goo.gl/ekMXJ β | |
| β£ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ« | |
| β 5 β Over-Educated Problems β 1625/343 β http://goo.gl/134ay β | |
| ββββββ»βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ»βββββββββββββ»βββββββββββββββββββββββ | |
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 'spec_helper' | |
| describe "CLI usage" do | |
| describe "redditor hot" do | |
| it "returns the hottest news on Reddit" do | |
| redditor "hot" | |
| output.should == read_fixture("output/redditor_hot.txt") | |
| end | |
| end | |
| 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
| require 'spec_helper' | |
| require 'redditor/version' | |
| describe Redditor do | |
| it "should have a VERSION constant" do | |
| subject.const_get('VERSION').should_not be_empty | |
| end | |
| 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
| require 'rspec' | |
| require 'active_support/core_ext/object' | |
| require 'support/cli_macros' | |
| require 'support/fixture_macros' |
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
| module Redditor | |
| class StoriesPrinter | |
| end | |
| 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
| module Redditor | |
| class Story | |
| def self.find(filters) | |
| get(url_for(filters)).map do |raw_story| | |
| Story.new(raw_story) | |
| end | |
| end | |
| end | |
| 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
| require 'spec_helper' | |
| require 'redditor/story' | |
| describe Redditor::Story do | |
| describe "#find" do | |
| it "gets the URL for the specified filters, and returns an array of Stories" do | |
| url = double("Reddit URL") | |
| raw_story = double("story hash") | |
| story = double("story") | |
| Redditor::Story.stub(:url_for).with(foo: :bar).and_return(url) | |
| Redditor::Story.stub(:get).with(url).and_return([ raw_story ]) | |
| Redditor::Story.stub(:new).with(raw_story).and_return(story) | |
| result = Redditor::Story.find(foo: :bar) | |
| result.should have(1).story | |
| result.first.should == story | |
| end | |
| end | |
| 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
| module Redditor | |
| # redditor version | |
| VERSION = "0.1.0" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment