opal-rspec 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30e47321597bd30772964731a69b644d2f3c1284
4
- data.tar.gz: dcd2c741e2717f11eb0f99c0ec1a1735bd8e0fc5
3
+ metadata.gz: a113f4e2300f7744e1a32478ffff2a68df90c4da
4
+ data.tar.gz: 9f58dbc325b688990d6cd2a5674a680bfa3340e8
5
5
  SHA512:
6
- metadata.gz: 1d51634479e56d629c70f8b689c34730e1268add0dd9b66a2af0a4a0e41813fcc54069e7330cae2785ec7e5e2937369e6496bce0d84d022983c4389418e8e335
7
- data.tar.gz: 600a4f9988f01ad15e7bfe9cd86e200104645c07ddf7fc97ba738ca521a83b396f39e058abff86e2215d01acccebdbf27fa768c88cddc16ed4ff9abab5807dfc
6
+ metadata.gz: bf0ba02df4d77fd5aa6fb2a81b7d016d9728c81716bafe61567824deecfde590934ef9450a287dba3b308d3e838fd87a3c2919d00317410eee75b7fba60ae09a
7
+ data.tar.gz: 5d09f7ea519a3bfd92a9b0974a029aa95cc1635e0ee9afce496b3356793e0c3454bc900bd58aecfa618ccb00cfcba74f2304a8f36ec6bd8e035f4973744ffc30
data/Gemfile CHANGED
@@ -3,10 +3,8 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
 
6
- # As we monkey patch a lot, work of a specific commit on github
7
- gem 'rspec-support', :github => 'rspec/rspec-support', :ref => 'f235ccb129'
8
- gem 'rspec-expectations', :github => 'rspec/rspec-expectations', :ref => 'd3277fd42e'
9
- gem 'rspec-core', :github => 'rspec/rspec-core', :ref => 'ed8898c58b'
10
- gem 'rspec-mocks', :github => 'rspec/rspec-mocks', :ref => 'a2f952a025'
11
-
12
- gem 'rspec', :github => 'rspec/rspec'
6
+ gem 'rspec', '3.0.0.beta1'
7
+ gem 'rspec-support', '3.0.0.beta1'
8
+ gem 'rspec-core', '3.0.0.beta1'
9
+ gem 'rspec-mocks', '3.0.0.beta1'
10
+ gem 'rspec-expectations', '3.0.0.beta1'
data/README.md CHANGED
@@ -4,6 +4,49 @@ An attempt at a compatibility layer of rspec for opal.
4
4
 
5
5
  ## Usage
6
6
 
7
+ Add `opal-rspec` to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'opal-rspec'
11
+ ```
12
+
13
+ ### Run specs in phantomjs
14
+
15
+ To run specs, a rake task can be added which will load all spec files from
16
+ `spec/`:
17
+
18
+ ```ruby
19
+ require 'opal/rspec/rake_task'
20
+ Opal::RSpec::RakeTask.new(:default)
21
+ ```
22
+
23
+ Then, to run your specs inside phantomjs, just run the rake task:
24
+
25
+ ```
26
+ bundle exec rake
27
+ ```
28
+
29
+ ### Run specs in a browser
30
+
31
+ `opal-rspec` can use sprockets to build and serve specs over a simple rack
32
+ server. Add the following to a `config.ru` file:
33
+
34
+ ```ruby
35
+ require 'bundler'
36
+ Bundler.require
37
+
38
+ run Opal::Server.new { |s|
39
+ s.main = 'opal/rspec/sprockets_runner'
40
+ s.append_path 'spec'
41
+ s.debug = false
42
+ }
43
+ ```
44
+
45
+ Then run the rack server `bundle exec rackup` and visit `http://localhost:9292`
46
+ in any web browser.
47
+
48
+ ## Contributing
49
+
7
50
  Install required gems at required versions:
8
51
 
9
52
  $ bundle install
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ def build_rspec
26
26
  Opal.use_gem 'rspec'
27
27
  Opal.use_gem 'rspec-expectations'
28
28
 
29
- %w[fileutils test/unit/assertions coderay optparse shellwords socket uri
29
+ %w[time fileutils test/unit/assertions coderay optparse shellwords socket uri
30
30
  drb/drb diff/lcs diff/lcs/hunk].each do |asset|
31
31
  Opal::Processor.stub_file asset
32
32
  end
data/app/rspec-builder.rb CHANGED
@@ -31,11 +31,13 @@ require 'rspec/core/example'
31
31
  require 'rspec/core/shared_example_group/collection'
32
32
  require 'rspec/core/shared_example_group'
33
33
  require 'rspec/core/example_group'
34
+
34
35
  require 'rspec/core'
35
36
  require 'rspec-expectations'
37
+ require 'rspec/mocks'
36
38
 
37
39
  # we want access to BaseFormatter
38
40
  require 'rspec/core/formatters/base_formatter'
39
41
 
40
42
  # For now, we don't support mocking. This placeholder in rspec-core allows that.
41
- require 'rspec/core/mocking/with_absolutely_nothing'
43
+ require 'rspec/core/mocking/with_rspec'
data/config.ru CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
+ require 'opal-sprockets'
5
+
4
6
  Opal::Processor.source_map_enabled = false
5
7
 
6
8
  run Opal::Server.new { |s|
@@ -1,6 +1,5 @@
1
1
  module Opal
2
2
  module RSpec
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
6
-
data/opal-rspec.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.require_paths = ['lib']
17
17
 
18
- s.add_dependency 'opal', '~> 0.5.0'
18
+ s.add_dependency 'opal', '>= 0.5.1'
19
19
  s.add_dependency 'opal-sprockets', '~> 0.3.0'
20
20
 
21
21
  s.add_development_dependency 'rake'
@@ -62,3 +62,17 @@ module RSpec::ExampleGroups
62
62
  name
63
63
  end
64
64
  end
65
+
66
+ # Opal does not support ObjectSpace, so force object __id__'s
67
+ class RSpec::Mocks::Space
68
+ def id_for(object)
69
+ object.__id__
70
+ end
71
+ end
72
+
73
+ # Buggy under Opal?
74
+ class RSpec::Mocks::MethodDouble
75
+ def save_original_method!
76
+ @original_method ||= @method_stasher.original_method
77
+ end
78
+ end
data/spec/mock_spec.rb ADDED
@@ -0,0 +1,52 @@
1
+ describe "RSpec mocks" do
2
+ describe "stubs" do
3
+ it "can stub basic methods" do
4
+ obj = Object.new
5
+ expect(obj).to receive(:foo) { 100 }
6
+ obj.foo.should == 100
7
+ end
8
+
9
+ it "raises an exception when stub returns wrong value" do
10
+ expect {
11
+ obj = Object.new
12
+ expect(obj).to receive(:bar) { 400 }
13
+ obj.bar.should == 42
14
+ }.to raise_error(Exception)
15
+ end
16
+
17
+ it "allow" do
18
+ obj = Object.new
19
+ allow(obj).to receive(:name) { "Adam B" }
20
+ allow(obj).to receive(:job).and_return("Eating Fruit Gums")
21
+
22
+ expect(obj.name).to eq("Adam B")
23
+ expect(obj.job).to eq("Eating Fruit Gums")
24
+ end
25
+
26
+ it "expecting arguments" do
27
+ person = double("person")
28
+ expect(person).to receive(:foo).with(4, 5, 6)
29
+ person.foo(4, 5, 6)
30
+ end
31
+ end
32
+
33
+ describe "doubles" do
34
+ it "define methods on double" do
35
+ person = double("person", :name => "Adam")
36
+ expect(person.name).to eq("Adam")
37
+ end
38
+
39
+ it "once" do
40
+ person = double("person")
41
+ expect(person).to receive(:name).once
42
+ person.name.should eq(nil)
43
+ end
44
+
45
+ it "twice" do
46
+ person = double("person")
47
+ expect(person).to receive(:name).twice
48
+ person.name
49
+ person.name.should
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-04 00:00:00.000000000 Z
11
+ date: 2013-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: 0.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0
26
+ version: 0.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opal-sprockets
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,7 @@ files:
80
80
  - spec/async_spec.rb
81
81
  - spec/example_spec.rb
82
82
  - spec/matchers_spec.rb
83
+ - spec/mock_spec.rb
83
84
  - vendor/spec_runner.js
84
85
  - opal/opal/rspec/rspec.js
85
86
  homepage: http://opalrb.org