maker_website 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a19be453dbb40b2c666d479e5b050e0324d627c
4
- data.tar.gz: e6a327784779cd7378c61627a6902a4ee355acb0
3
+ metadata.gz: 46b9d18e9fcf7fd16f8279aa19e4e5dc15baa7ef
4
+ data.tar.gz: 8a719726030976c471bed0d78a5a4090b436775e
5
5
  SHA512:
6
- metadata.gz: f756f40265dfe9c4a42a332c4543d6fac13882ff3c0a94a1e761e5842381529194ad62d0da933a8cce7e3123b02105c0cb21cb9a4bd0ea0fc1a0ea5f9c8c2023
7
- data.tar.gz: 4ba159db4625f904c89a7621cbba29441474f4c44a5bad883642ed34b13643d3485e805ea4dbec83258248c1266b17311e0687301e6664c373c30db48086f203
6
+ metadata.gz: 9e6673cdc470f31d090cf84075a26596a8f162afb7f463c78c6b0c16c12b66191ebaa12e18d89835a53b61e2c54f1b676a83574cb91ad9c92c3dd2aa4b8a430a
7
+ data.tar.gz: e78d615ed1121312664ddfd7a49dfe2ba9a921fde637534de5d77ac4e0993fd0803cb10ea780d293aef1d71b29e8428541c099b64b2e4b78b6483aaf9cf7a050
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .maker
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --require maker_website
data/exe/maker CHANGED
@@ -1,27 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rspec'
4
- require 'rspec/core/formatters/json_formatter'
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+
6
+ require_relative '../lib/maker_website'
7
+
8
+ program :version, '0.0.1'
9
+ program :description, 'Makers Academy student command line interface'
10
+
11
+ command :register do |c|
12
+ c.syntax = 'maker register EMAIL'
13
+ c.summary = ''
14
+ c.description = ''
15
+ c.example 'description', 'command example'
16
+ c.when_called Maker::Commands::Register
17
+ end
18
+
19
+ command :verify do |c|
20
+ c.syntax = 'maker verify [options]'
21
+ c.summary = ''
22
+ c.description = ''
23
+ c.example 'description', 'command example'
24
+ c.option '--some-switch', 'Some switch that does something'
25
+ c.when_called Maker::Commands::Verify
26
+ end
5
27
 
6
- config = RSpec.configuration
7
-
8
- formatter = RSpec::Core::Formatters::JsonFormatter.new(config.output_stream)
9
-
10
- # create reporter with json formatter
11
- reporter = RSpec::Core::Reporter.new(config)
12
- config.instance_variable_set(:@reporter, reporter)
13
-
14
- # internal hack
15
- # api may not be stable, make sure lock down Rspec version
16
- loader = config.send(:formatter_loader)
17
- notifications = loader.send(:notifications_for,
18
- RSpec::Core::Formatters::JsonFormatter)
19
-
20
- reporter.register_listener(formatter, *notifications)
21
-
22
-
23
- spec_file = File.expand_path( "../lib/maker_website/website_spec.rb", File.dirname(__FILE__))
24
- RSpec::Core::Runner.run([spec_file])
25
-
26
- # here's your json hash
27
- p formatter.output_hash
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ module Maker
4
+ class Client
5
+ FILE_NAME = './.maker'
6
+
7
+ def save(data)
8
+ File.write(FILE_NAME, data.to_yaml)
9
+ @data = nil
10
+ end
11
+
12
+ def data
13
+ @data ||= load_data
14
+ end
15
+
16
+ def registered?
17
+ !!fields['email']
18
+ end
19
+
20
+ def fields
21
+ data[data.keys.first] || {}
22
+ end
23
+
24
+ private
25
+
26
+ def load_data
27
+ if File.exists? FILE_NAME
28
+ YAML.load(File.read(FILE_NAME))
29
+ else
30
+ {}
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module Maker
2
+ module Commands
3
+ class Register
4
+ attr_reader :email
5
+
6
+ def initialize(args, options)
7
+ @email = args.first
8
+ run
9
+ end
10
+
11
+ def run
12
+ student = server.student
13
+
14
+ client.save(student)
15
+ end
16
+
17
+ def server
18
+ @server ||= Server.new(email)
19
+ end
20
+
21
+ def client
22
+ @client ||= Client.new
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ require 'commander/import'
2
+
3
+ module Maker
4
+ module Commands
5
+ class Verify
6
+ def initialize(args, options)
7
+ run
8
+ end
9
+
10
+ def run
11
+ fail Maker::NotRegisteredError unless client.registered?
12
+ @results = MakerWebsite::RunRSpec.with(file_name: file_name)
13
+ handle_results
14
+ end
15
+
16
+ def server
17
+ @server ||= Maker::Server.new(client.fields['email'])
18
+ end
19
+
20
+ def client
21
+ @client ||= Maker::Client.new
22
+ end
23
+
24
+ def stage
25
+ client.fields['stage']
26
+ end
27
+
28
+ private
29
+
30
+ def handle_results
31
+ @results[:summary][:failure_count] > 0 ? handle_failure : handle_success
32
+ end
33
+
34
+ def handle_failure
35
+ say 'You haven\'t completed this stage yet, please see the test results below:'
36
+ @results[:examples].select {|example| example[:status] = 'failed'}.each do |example|
37
+ say "Feature: #{example[:full_description]}"
38
+ say "Issue: #{example[:exception][:message]}"
39
+ end
40
+ end
41
+
42
+ def handle_success
43
+ say "Congratulations! Stage #{stage} complete!"
44
+ next_stage
45
+ say "Stage #{stage} is now unlocked - good luck!"
46
+ end
47
+
48
+ def next_stage
49
+ server.next_stage
50
+ client.save(server.student)
51
+ end
52
+
53
+ def file_name
54
+ "stage_#{stage}_spec.rb"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,40 @@
1
+ require 'firebase'
2
+
3
+ module Maker
4
+ class Server
5
+ attr_reader :email
6
+
7
+ def initialize(email)
8
+ @email = email
9
+ end
10
+
11
+ def student
12
+ @student ||= load_student
13
+ end
14
+
15
+ def firebase
16
+ @firebase ||= Firebase::Client.new('https://resplendent-fire-7855.firebaseio.com')
17
+ end
18
+
19
+ def next_stage
20
+ fields['stage'] += 1
21
+ firebase.set("students/#{student_id}", fields)
22
+ end
23
+
24
+ def fields
25
+ student[student_id] || {}
26
+ end
27
+
28
+ private
29
+
30
+ def student_id
31
+ student.keys.first
32
+ end
33
+
34
+ def load_student
35
+ response = firebase.get('students', orderBy: "\"email\"", startAt: "\"#{email}\"", endAt: "\"#{email}\"")
36
+ fail 'could not fetch email address from server' unless response.success?
37
+ response.body
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,14 @@
1
1
  require "maker_website/version"
2
+ require 'maker_website/run_rspec'
3
+ require 'maker/commands/register'
4
+ require 'maker/commands/verify'
5
+ require 'maker/client'
6
+ require 'maker/server'
2
7
 
3
8
  module MakerWebsite
4
9
  # Your code goes here...
5
10
  end
11
+
12
+ module Maker
13
+ class NotRegisteredError < StandardError; end
14
+ end
@@ -0,0 +1,55 @@
1
+ require 'rspec'
2
+ require 'rspec/core/formatters/json_formatter'
3
+
4
+ # Capybara stuff
5
+ require 'capybara'
6
+ require 'capybara/rspec'
7
+
8
+ module MakerWebsite
9
+ class RunRSpec
10
+ attr_reader :file_name
11
+
12
+ def self.with(file_name:)
13
+ self.new(file_name).run
14
+ end
15
+
16
+ def initialize(file_name)
17
+ @file_name = file_name
18
+ end
19
+
20
+ def run
21
+ reporter.register_listener(formatter, *notifications)
22
+ RSpec::Core::Runner.run([spec_file])
23
+
24
+ formatter.output_hash
25
+ end
26
+
27
+ def spec_file
28
+ @spec_file ||= File.expand_path( "stages/#{file_name}", File.dirname(__FILE__))
29
+ end
30
+
31
+ private
32
+
33
+ def config
34
+ @config ||= RSpec.configuration
35
+ end
36
+
37
+ def formatter
38
+ @formatter ||= RSpec::Core::Formatters::JsonFormatter.new(StringIO.new)
39
+ end
40
+
41
+ def reporter
42
+ # create reporter with json formatter
43
+ @reporter ||= RSpec::Core::Reporter.new(config)
44
+ config.instance_variable_set(:@reporter, @reporter)
45
+ end
46
+
47
+ def notifications
48
+ # internal hack
49
+ # api may not be stable, make sure lock down Rspec version
50
+ @loader ||= config.send(:formatter_loader)
51
+ @notifications ||= @loader.send(:notifications_for,
52
+ RSpec::Core::Formatters::JsonFormatter)
53
+ end
54
+ end
55
+ end
@@ -1,14 +1,7 @@
1
- # Capybara stuff
2
- require 'capybara'
3
- require 'capybara/rspec'
4
1
  require './server'
5
2
 
6
3
  Capybara.app = Sinatra::Application.new
7
4
 
8
- def app
9
- Sinatra::Application
10
- end
11
-
12
5
  feature "Hello world" do
13
6
  scenario "it works" do
14
7
  visit "/"
@@ -1,3 +1,3 @@
1
1
  module MakerWebsite
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
Binary file
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency 'rspec'
24
24
  spec.add_runtime_dependency 'capybara'
25
+ spec.add_runtime_dependency 'firebase'
26
+ spec.add_runtime_dependency 'commander'
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maker_website
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Forrest
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-29 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: firebase
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: commander
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description:
70
98
  email:
71
99
  - ben@silvabox.com
@@ -75,16 +103,23 @@ extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
105
  - ".gitignore"
106
+ - ".rspec"
78
107
  - Gemfile
79
108
  - README.md
80
109
  - Rakefile
81
110
  - bin/console
82
111
  - bin/setup
83
112
  - exe/maker
113
+ - lib/maker/client.rb
114
+ - lib/maker/commands/register.rb
115
+ - lib/maker/commands/verify.rb
116
+ - lib/maker/server.rb
84
117
  - lib/maker_website.rb
118
+ - lib/maker_website/run_rspec.rb
119
+ - lib/maker_website/stages/stage_1_spec.rb
85
120
  - lib/maker_website/version.rb
86
- - lib/maker_website/website_spec.rb
87
121
  - maker_website-0.1.1.gem
122
+ - maker_website-0.1.2.gem
88
123
  - maker_website.gemspec
89
124
  homepage: http://www.makersacademy.com
90
125
  licenses: []