1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
Commit graph

31 commits

Author SHA1 Message Date
robert
ed94afb476 fix bug discovered while investigating #1552 2016-07-09 02:54:03 +01:00
strcmp
46f24c3f77 change from_hash to be recursive. 2015-08-17 10:15:14 +01:00
strcmp
41d8e86dc2 reference bug # in spec. 2015-07-27 16:10:13 +01:00
strcmp
39bbfa9e63 add API docs; remove old 'refresh' alias. 2015-07-27 12:57:29 +01:00
strcmp
c49d031c64 add ReservedKeyError; reserve more keys. 2015-07-27 12:19:35 +01:00
Kyrylo Silin
96c6958cc6 specs: convert to shoulds to expects 2015-03-10 22:49:29 +02:00
Matijs van Zuijlen
96b61f14aa Fix some warnings 2015-01-23 14:03:36 +01:00
rpag
27e9199dbb fixes #1277 2014-12-13 16:36:17 +00:00
rpag
1486996a84 Behavior#[] traverses through chain of defaults.
_pry_.config['output'] returns $stdout, by traversing back to
Pry::Config::Default#output.
2014-12-13 14:40:33 +00:00
Josh Cheek
144d32e1d6 Switch test suite to RSpec
Removes Bacon and Mocha

Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712

Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)

The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block.  In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do

This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 17:37:21 -06:00
Josh Cheek
d8490e8f53 Fix Pry.config.hooks # => parent's hooks
PROBLEM DESCRIPTION
===================

The child caches a dup of the parent's hooks,
so it does the correct thing after being accessed the first time.

But the first time it is called, it doesn't return its cached duped value,
it returns the parent's value. This causes 2 bugs:

1. The first hook declared will get "lost", because it is declared
   to the parent hooks, not the child's hooks. And after that first
   accessing, only the child's hooks will be used
2. The parent's hooks (which are probably the ones from
   [the default](0ff6fa61d4/lib/pry/config/default.rb (L35-37)))
   are going to get hooks declared on them that shouldn't be
   (well, presumably shouldn't be, given the explicit check for
   this case and duping to avoid it).
   So if another config object was initialized with the same parent,
   it would wind up with hooks that it didn't want/expect.

I assume all the other keys work fine because they are value objects,
so if anything wanted to change the value, it would reassign the key
to the config object rather than mutating the returned value.

Mutability *sigh* yallknowwhatimsayin

SOLUTION DESCRIPTION
====================

Return the cached duped child value instead of the parent value.

EXAMPLE
=======

This code from
[the docs](0ff6fa61d4/lib/pry/hooks.rb (L8-11))
will not print "hello", because it's being declared to the parent hook.

```ruby
Pry.config.hooks.add_hook(:before_session, :say_hi) { puts "hello" }
```

This code will, b/c it's being declared to the cached, duped child hook.

```ruby
Pry.config.hooks
Pry.config.hooks.add_hook(:before_session, :say_hi) { puts "hello" }
```

ISSUE IMPACT
============

Fixes #1254

Might fix or have something to do with these issues:

* #1244 Totally thought I got it, but then couldn't reproduce again later
  and just don't understand how JRuby builds, so might just be a problem
  with how I was trying to reproduce it.
* #1171 Maybe, depending on if Eclipse integrates with it using the
  hooks, alternatively, could be the same issue as the one above,
  they might both still be broken. Or both fixed and I can't figure out
  how to prove it. Dunno.

OTHER THOUGHTS
==============

I'm writing Github flavoured markdown,
but I'm not actually sure if it will get rendered as such in the PR.
Esp since git considers leading octothorpes as comments and not headers,
and removes them...

Guess we'll see... bottoms up, friends!
2014-07-20 17:18:12 -06:00
Conrad Irwin
2202ab775c Move to a fall-through config hash.
This is somewhat easier to understand than the current solution,
but does have some downsides: namely it doesn't work for things like
Pry::Hooks.

It is however the only way I've thought of to let setting
Pry.config.color = work in addition to _pry.config.color =.

For now I've added a hack so that hooks work as they did before,
in future we should work out how to fix them so that only the data
for hooks is stored in the config object, not the hooks object itself.
2014-05-01 01:51:01 -07:00
Robert Gleeson
9585f795cf return Method objects for keys set and written at runtime 2014-03-23 10:16:13 +01:00
Robert Gleeson
b5f0cfa0a2 support either #to_h or #to_hash in Behavior#merge! 2014-03-23 09:02:10 +01:00
Robert Gleeson
7e6f9e3ec3 alias clear as 'refresh'. 2014-03-15 03:05:19 +01:00
Robert Gleeson
98a418bec7 add 'default' to the list of reserved keys & improve err msg. 2014-03-14 09:15:58 +01:00
Robert Gleeson
d0faf8b2d0 add Pry::Config::Behavior#default. 2014-03-14 05:41:14 +01:00
Robert Gleeson
74135c1890 allow for tests to be run with ease.
'bacon spec/config_spec.rb' instead of 'bacon -I spec spec/config_spec.rb'
2014-03-14 05:31:24 +01:00
Robert Gleeson
76d4f03934 add Behavior#keys. 2014-02-02 23:23:23 +01:00
Robert Gleeson
41a90bd93b forgot to set an explicit default of nil. 2014-02-02 15:58:10 +01:00
Robert Gleeson
8e723512dd duplicate Hash returned by Behavior#to_hash (prevents outside-mutation) 2014-02-02 15:34:35 +01:00
Robert Gleeson
557cd0fa7b return false when argument does not implement #to_hash. 2014-02-02 15:01:32 +01:00
Robert Gleeson
6591ddd418 add tests. 2014-02-02 14:52:55 +01:00
Robert Gleeson
4d39a53e61 specify 'nil' default in config_spec.rb (don't fallback on Pry.config) 2014-02-01 03:16:12 +01:00
Robert Gleeson
04444b7bb7 add tests for config. 2014-01-31 14:18:32 +01:00
Robert Gleeson
a6783e2628 add config test for traversal through chain of parents. 2014-01-31 14:12:04 +01:00
Robert Gleeson
0a25818c6b cleanup in config_spec.rb 2014-01-31 02:43:13 +01:00
Robert Gleeson
929c3f5aaa add spec's for Pry::Config. 2014-01-31 02:39:23 +01:00
Robert Gleeson
e3f2475671 extend RESERVED_KEYS tests. 2014-01-30 01:41:56 +01:00
Robert Gleeson
4ba451fef5 guard against the assignment of reserved keys (add Behavior::RESERVED_KEYS). 2014-01-27 10:06:06 +01:00
yui-knk
9da6c98fd6 Add spec for Pry::Config 2014-01-22 00:32:03 +09:00