Comments (4)
@elia - Sound interesting? I think it could start as a monkey patch but maybe the compiler could add a framework some day.
from opal-rspec.
Does opal-rspec support latest opal master? If it does you can do it with a custom AST rewriter:
class RSpecMetadataRewriter < Opal::Rewriters::Base
RSPEC_METHODS = %i(describe context it)
def on_send(node)
node = super
recv, meth, *args = *node
if RSPEC_METHODS.include?(meth)
file = node.loc.expression.source_buffer.name
line = node.loc.line
column = node.loc.column
loc_metadata = "#{file}:#{line}:#{column}"
loc_metadata_pair = s(:pair, s(:sym, :loc), s(:str, loc_metadata))
if args.last.type == :iter
*args, iter = *args
end
if args.last.type == :hash
*args, last_hash_arg = *args
else
last_hash_arg = s(:hash)
end
pairs = *last_hash_arg
pairs += [loc_metadata_pair]
last_hash_arg = last_hash_arg.updated(nil, pairs)
args = [*args, last_hash_arg, iter].compact
node.updated(nil, [recv, meth, *args])
else
node
end
end
end
Opal::Rewriter::LIST << RSpecMetadataRewriter
test.rb:
def describe(*args)
puts "describe"
puts args
yield
end
def context(*args)
puts "context"
puts args
yield
end
def it(*args)
puts "it"
puts args
end
describe 'MyClass1', type: :some_type do
context 'when something happens' do
it 'does the following'
end
end
➜ opal git:(master) ✗ opal test.rb
describe
["MyClass1", {"type"=>"some_type", "loc"=>"test:18:0"}]
context
["when something happens", {"loc"=>"test:19:2"}]
it
["does the following", {"loc"=>"test:20:4"}]
➜ opal git:(master) ✗ opal ../opal/test.rb
describe
["MyClass1", {"type"=>"some_type", "loc"=>"../opal/test:18:0"}]
context
["when something happens", {"loc"=>"../opal/test:19:2"}]
it
["does the following", {"loc"=>"../opal/test:20:4"}]
from opal-rspec.
It did but it's currently broken (Sprockets is the first reason).
from opal-rspec.
I'm inclined to rely on source-maps for browser and possibly for node too.
from opal-rspec.
Related Issues (20)
- Performance Improvement Ideas HOT 4
- issues with opal 0.10.0 HOT 4
- Results Reporting Sync/Async HOT 1
- filter_run_excluding not working? HOT 1
- how to require gem or a source file ? HOT 5
- stub_const doesn't work quite the same in opal 0.9 HOT 9
- Opal-Master Compatibility
- Sprockets HOT 1
- Support random order HOT 2
- Opal::RSpec::RakeTask HOT 4
- `expect_any_instance_of` is not working when using opal master HOT 5
- Trying to run phantomjs or in-browser tests throws Sprockets::FileNotFound HOT 3
- Get ` cannot load such file -- rake` when run test in browser. HOT 2
- Could not found jquery when use node as task runner. HOT 1
- spec not worked with opal 0.11. (chrome headless) HOT 11
- Unable to require 'nodejs' in spec HOT 2
- uninitialized constant OPAL_PLATFORM HOT 8
- Headless Chrome support HOT 3
- Can you release a new version? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opal-rspec.