motion-spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGJkZjNkZGM5YWUxMzcwYjkzOTY2Y2U3YmMwNmVjMGIwY2RmZGNiYg==
5
+ data.tar.gz: !binary |-
6
+ ZGUyNDg4ZmY1NWYwNDNmMGUzNGY2ZDg1NzFhM2QxZjBkYzA4NTRhOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTEzYTc5MjI5Y2M1MjA2NjQyNjAzODM0YzE5N2VjMDc3MTYxMGUwOWM3NWQw
10
+ Y2U1MmRkZTY1ZDJlYjFmMzFmYzc4YzlmNTVlZDI1ZTUxMWEwMWU4NWIxN2Yy
11
+ NzhlZTFjN2Q3YWNmNzhlMWFmZmRjODY3YTczZTFmZWNkNGJjYjI=
12
+ data.tar.gz: !binary |-
13
+ NmYyYzE5YWVlNmY5MjRhODY0ZDc3YjIwNGQ3NWE0NDc1MmM4MmYzOTg0MGI2
14
+ ZTY3N2FiNDQzOTQ2OWFhN2YzZThlZjZhMTFhNTRmMjg2NzRiMTc1NzZiMGJk
15
+ ZmU3NzcyOWEzMGZmZDY3YjA0OTVkODMxYWVhOGNmZGQ3ZGU2ZWM=
data/.codeclimate.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ engines:
3
+ rubymotion:
4
+ enabled: true
5
+ rubocop:
6
+ enabled: true
7
+ bundler-audit:
8
+ enabled: true
9
+ ratings:
10
+ paths:
11
+ - "**.rb"
12
+ - Gemfile.lock
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ # OSX
38
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,58 @@
1
+ # Disable all checks not explicitly referenced in this file
2
+ # This is used to easily disable Style/* checks
3
+ AllCops:
4
+ Lint: true
5
+ Metrics: true
6
+ Performance: true
7
+ Rails: false
8
+ Style: true
9
+
10
+ ##########################################################
11
+ Metrics/AbcSize:
12
+ Description: >-
13
+ A calculated magnitude based on number of assignments,
14
+ branches, and conditions.
15
+ Reference: 'http://c2.com/cgi/wiki?AbcMetric'
16
+ Enabled: true
17
+ Max: 25
18
+
19
+ Metrics/BlockNesting:
20
+ Description: 'Avoid excessive block nesting'
21
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
22
+ Enabled: true
23
+ Max: 4
24
+
25
+ Metrics/ClassLength:
26
+ Description: 'Avoid classes longer than 100 lines of code.'
27
+ Enabled: true
28
+ Max: 100
29
+
30
+ Metrics/ModuleLength:
31
+ Description: 'Avoid modules longer than 100 lines of code.'
32
+ Enabled: true
33
+ Max: 100
34
+
35
+ Metrics/MethodLength:
36
+ Description: 'Avoid methods longer than 20 lines of code.'
37
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
38
+ Enabled: false
39
+ Max: 10
40
+
41
+ Metrics/ParameterLists:
42
+ Description: 'Avoid parameter lists longer than three or four parameters.'
43
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params'
44
+ Enabled: false
45
+
46
+ Style/EmptyLineBetweenDefs:
47
+ AllowAdjacentOneLineDefs: true
48
+
49
+ Style/IndentationWidth:
50
+ Description: 'Use 2 spaces for indentation.'
51
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
52
+ Enabled: true
53
+
54
+ Style/MethodName:
55
+ Enabled: false
56
+
57
+ Style/VariableName:
58
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: objective-c
2
+
3
+ matrix:
4
+ include:
5
+ - osx_image: xcode7.1
6
+ - osx_image: xcode7
7
+ - osx_image: xcode6.4
8
+
9
+ script: bundle exec rake spec
10
+
11
+ deploy:
12
+ provider: rubygems
13
+ api_key:
14
+ secure: TkxLEf5WwpFSevhXXSKMgMU4itZ03sR2d3k6z0VPiDz1ieRIcCpdSkB5HtPb7qqR3uklFSHXLvJPLGoSMElA6V4iYWmX4vpIIu3RMSCBs5AjfbdbAr6w4KDiHhatDgD9m7p0iPV1r3Q/AHVtVCT4zrJP+GC9/rXXEwqM0j4fQLuCMuvMiikLck6Xk3/eYJuKoW2TfzHihB+b7rSuG3w55Y0Yej5u2GMakoJpm2jo8Iu5kdIWEWckb82zrXJZ//AefI0GsMmYFnndCaJC21Q+l3yTcuQ3q/0Ccql0O7fg+wWSKd8y7X3+vcpYCL+erGxRqyCz1+lfxWHPgSPYjRlXp7VhbAgOJV+n4oFvZw/uHNiUlmpiHytTVp6qAHMiT9yxg5yY3QltZHPCn9m5+xHDOw4apISVtMchoQnfrzX1g7QpBZfbRBgWpxLNcbF0VzBse0cKqfU1Z1NiWScp/dJp7hhqEEgHKjk9IIq4OWoUw2+HbsLf9lKScAoRhvdMIwg0PliQsySXgmlxtPehQFAyEsh6qMrxpqwqzeoLbfkOLU1MPO4Ob7e21ewoK886FoSZe1bQ6pnIFnkwY8jcyXgLRSNAy249Qz1N0tjl+olNsK7fXeHeaS0X4GIeWbBd4gFT5VTfLQPNLOzdzswUtrobWSviYPcbcKJssjAfOHvD4u4=
15
+ gem: motion-spec
16
+ on:
17
+ tags: true
18
+ repo: jbender/motion-spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in motion-spec.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ motion-spec (0.1.0)
5
+ motion-require (>= 0.0.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ motion-require (0.2.0)
11
+ rake (10.4.2)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ motion-spec!
18
+ rake (~> 10.0)
19
+
20
+ BUNDLED WITH
21
+ 1.10.5
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2007, 2008 Christian Neukirchen <purl.org/net/chneukirchen>
4
+ Copyright (c) 2011 Eloy Durán <eloy.de.enige@gmail.com>
5
+ Copyright (c) 2015 Jonathan Bender <jlbender@gmail.com>
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # MotionSpec
2
+ [![Build Status](https://img.shields.io/travis/jbender/motion-spec/master.svg)](https://travis-ci.org/jbender/motion-spec)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/jbender/motion-spec.svg)](https://codeclimate.com/github/jbender/motion-spec)
4
+ [![MIT Licensed](https://img.shields.io/github/license/jbender/motion-spec.svg)](https://github.com/jbender/motion-spec/blob/master/LICENSE)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/jbender/motion-spec.svg)](https://gemnasium.com/jbender/motion-spec)
6
+
7
+ Specs are important! This project makes them a first-class citizen again.
8
+
9
+ RubyMotion is great at integrating them from the start, but
10
+ they aren't core to the RubyMotion workflow, and lag behind their distant
11
+ `rspec` cousin (RubyMotion's specs are forked from `MacBacon`, which is a port
12
+ of `Bacon` which is a simplified version of `rspec`).
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'motion-spec'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install motion-spec
29
+
30
+ ## Usage
31
+
32
+ TODO: Write usage instructions here
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at
37
+ https://github.com/jbender/motion-spec.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ $:.unshift('/Library/RubyMotion/lib')
3
+ require 'motion/project/template/ios'
4
+ require 'bundler/gem_tasks'
5
+ Bundler.setup
6
+ Bundler.require
7
+
8
+ require 'motion-spec'
9
+
10
+ Motion::Project::App.setup do |app|
11
+ # Use `rake config' to see complete project settings.
12
+ app.name = 'MotionSpec'
13
+ app.detect_dependencies = false
14
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class AppDelegate
3
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
4
+ true
5
+ end
6
+ end
@@ -0,0 +1,77 @@
1
+ # -*- encoding : utf-8 -*-
2
+ unless defined?(Motion::Project::Config)
3
+ raise 'The MotionSpec gem must be required within a RubyMotion project Rakefile.'
4
+ end
5
+
6
+ require 'motion-require'
7
+
8
+ # Proper load order of all the classes/modules
9
+ ###
10
+
11
+ # Let's start off with what version we're running
12
+ Motion::Require.all('lib/motion-spec/version.rb')
13
+
14
+ # Load the output before the core so the core knows how to print
15
+ Motion::Require.all(Dir.glob('lib/motion-spec/output/*.rb'))
16
+
17
+ # All the other core modules in the proper order
18
+ Motion::Require.all([
19
+ 'lib/motion-spec/core.rb',
20
+ 'lib/motion-spec/error.rb',
21
+ 'lib/motion-spec/specification.rb',
22
+ 'lib/motion-spec/platform.rb',
23
+ 'lib/motion-spec/context.rb',
24
+ 'lib/motion-spec/should.rb'
25
+ ])
26
+
27
+ # Monkeypatch core objects to respond to test methods
28
+ Motion::Require.all(Dir.glob('lib/motion-spec/extensions/*.rb'))
29
+
30
+ # FIXME : Need better detection for iPhone Simulator
31
+ if defined?(UIDevice) &&
32
+ UIDevice.respond_to?('currentDevice') &&
33
+ !UIDevice.currentDevice.name =~ /(iPhone|iPad) Simulator/
34
+
35
+ module Kernel
36
+ def puts(*args)
37
+ NSLog(args.join("\n"))
38
+ end
39
+
40
+ def print(*args)
41
+ puts *args # TODO
42
+ end
43
+ end
44
+ end
45
+
46
+ # Remove the 'spec' file from the core load path so that the copy of 'Bacon'
47
+ # included in RubyMotion is not automatically loaded. That file not only adds
48
+ # Bacon but monkeypatches things like Kernel.describe that we don't want.
49
+ module Motion
50
+ module Project
51
+ class Config
52
+ def spec_core_files
53
+ @spec_core_files ||= begin
54
+ # Core library + core helpers.
55
+ Dir.chdir(File.join(File.dirname(__FILE__), '..')) do
56
+ # NOTE: This line is commented out to avoid loading Bacon.
57
+ ( # ['spec.rb'] +
58
+ Dir.glob(File.join('spec', 'helpers', '*.rb')) +
59
+ Dir.glob(File.join('project', 'template', App.template.to_s, 'spec-helpers', '*.rb'))).
60
+ map { |x| File.expand_path(x) }
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ # 'Bacon' is hard-coded in the string generated by main_cpp_file_txt as
67
+ # the class to run our specs. This updates the method to replace 'Bacon'
68
+ # with 'MotionSpec'.
69
+ class IOSConfig
70
+ alias_method :old_main_cpp_file_txt, :main_cpp_file_txt
71
+
72
+ def main_cpp_file_txt(spec_objs)
73
+ old_main_cpp_file_txt(spec_objs).gsub(/Bacon/, 'MotionSpec')
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,135 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module MotionSpec
3
+ class Context
4
+ attr_reader :name, :block
5
+
6
+ def initialize(name, before = nil, after = nil, &block)
7
+ @name = name
8
+ @before = before ? before.dup : []
9
+ @after = after ? after.dup : []
10
+ @block = block
11
+ @specifications = []
12
+ @current_specification_index = 0
13
+
14
+ MotionSpec.add_context(self)
15
+
16
+ instance_eval(&block)
17
+ end
18
+
19
+ def run
20
+ # TODO
21
+ # return unless name =~ RestrictContext
22
+
23
+ if Platform.android?
24
+ @specifications.each(&:run)
25
+ else
26
+ spec = current_specification
27
+ return spec.performSelector('run', withObject: nil, afterDelay: 0) if spec
28
+ end
29
+
30
+ MotionSpec.context_did_finish(self)
31
+ end
32
+
33
+ def current_specification
34
+ @specifications[@current_specification_index]
35
+ end
36
+
37
+ def specification_did_finish(spec)
38
+ return if Platform.android?
39
+
40
+ if (@current_specification_index + 1) < @specifications.size
41
+ @current_specification_index += 1
42
+ return run
43
+ end
44
+
45
+ MotionSpec.context_did_finish(self)
46
+ end
47
+
48
+ def before(&block)
49
+ @before << block
50
+ end
51
+
52
+ def after(&block)
53
+ @after << block
54
+ end
55
+
56
+ def behaves_like(*names)
57
+ names.each { |name| instance_eval(&Shared[name]) }
58
+ end
59
+
60
+ def it(description, &block)
61
+ return unless description =~ RestrictName
62
+ block ||= proc { should.flunk 'not implemented' }
63
+ Counter[:specifications] += 1
64
+ @specifications << Specification.new(self, description, block, @before, @after)
65
+ end
66
+
67
+ def should(*args, &block)
68
+ return it('should ' + args.first, &block) if Counter[:depth] == 0
69
+
70
+ super(*args, &block)
71
+ end
72
+
73
+ def describe(*args, &block)
74
+ context = MotionSpec::Context.new("#{@name} #{args.join(' ')}", @before, @after, &block)
75
+
76
+ # FIXME: fix RM-879 and RM-806
77
+ build_ios_parent_context(context) unless Platform.android?
78
+
79
+ context
80
+ end
81
+ alias_method :context, :describe
82
+
83
+ def wait(seconds = nil, &block)
84
+ return current_specification.schedule_block(seconds, &block) if seconds
85
+
86
+ current_specification.postpone_block(&block)
87
+ end
88
+
89
+ def wait_max(timeout, &block)
90
+ current_specification.postpone_block(timeout, &block)
91
+ end
92
+
93
+ def wait_for_change(object_to_observe, key_path, timeout = 1, &block)
94
+ current_specification.postpone_block_until_change(
95
+ object_to_observe,
96
+ key_path,
97
+ timeout,
98
+ &block
99
+ )
100
+ end
101
+
102
+ def resume
103
+ current_specification.resume
104
+ end
105
+
106
+ def raise?(*args, &block)
107
+ block.raise?(*args)
108
+ end
109
+
110
+ def throw?(*args, &block)
111
+ block.throw?(*args)
112
+ end
113
+
114
+ def change?(*args, &block)
115
+ block.change?(*args)
116
+ end
117
+
118
+ # Android-only.
119
+ def main_activity
120
+ MotionSpec.main_activity
121
+ end
122
+
123
+ private
124
+
125
+ def build_ios_parent_context(context)
126
+ (parent_context = self).methods(false).each do |e|
127
+ class << context
128
+ self
129
+ end.send(:define_method, e) do |*args|
130
+ parent_context.send(e, *args)
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end